OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This is a tool used by register_host.py to generate RSA keypair. It just | 5 // This is a tool used by register_host.py to generate RSA keypair. It just |
6 // generates new keys and prints them on stdout. | 6 // generates new keys and prints them on stdout. |
7 // | 7 // |
8 // This code will need to be integrated with the host registration UI. | 8 // This code will need to be integrated with the host registration UI. |
9 | 9 |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
15 #include "base/base64.h" | 15 #include "base/base64.h" |
16 #include "base/crypto/rsa_private_key.h" | 16 #include "crypto/rsa_private_key.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 | 18 |
19 int main(int argc, char** argv) { | 19 int main(int argc, char** argv) { |
20 base::AtExitManager exit_manager; | 20 base::AtExitManager exit_manager; |
21 | 21 |
22 scoped_ptr<base::RSAPrivateKey> key(base::RSAPrivateKey::Create(2048)); | 22 scoped_ptr<crypto::RSAPrivateKey> key(crypto::RSAPrivateKey::Create(2048)); |
23 | 23 |
24 std::vector<uint8> private_key_buf; | 24 std::vector<uint8> private_key_buf; |
25 key->ExportPrivateKey(&private_key_buf); | 25 key->ExportPrivateKey(&private_key_buf); |
26 std::string private_key_str(private_key_buf.begin(), private_key_buf.end()); | 26 std::string private_key_str(private_key_buf.begin(), private_key_buf.end()); |
27 std::string private_key_base64; | 27 std::string private_key_base64; |
28 base::Base64Encode(private_key_str, &private_key_base64); | 28 base::Base64Encode(private_key_str, &private_key_base64); |
29 printf("%s\n", private_key_base64.c_str()); | 29 printf("%s\n", private_key_base64.c_str()); |
30 | 30 |
31 std::vector<uint8> public_key_buf; | 31 std::vector<uint8> public_key_buf; |
32 key->ExportPublicKey(&public_key_buf); | 32 key->ExportPublicKey(&public_key_buf); |
33 std::string public_key_str(public_key_buf.begin(), public_key_buf.end()); | 33 std::string public_key_str(public_key_buf.begin(), public_key_buf.end()); |
34 std::string public_key_base64; | 34 std::string public_key_base64; |
35 base::Base64Encode(public_key_str, &public_key_base64); | 35 base::Base64Encode(public_key_str, &public_key_base64); |
36 printf("%s\n", public_key_base64.c_str()); | 36 printf("%s\n", public_key_base64.c_str()); |
37 } | 37 } |
OLD | NEW |