[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | e354d2c | 2010-07-14 21:38:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | // |
| 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. |
| 7 | // |
| 8 | // This code will need to be integrated with the host registration UI. |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | |
| 12 | #include <vector> |
| 13 | |
| 14 | #include "base/at_exit.h" |
| 15 | #include "base/base64.h" |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 16 | #include "crypto/rsa_private_key.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 17 | #include "base/memory/scoped_ptr.h" |
[email protected] | e354d2c | 2010-07-14 21:38:31 | [diff] [blame] | 18 | |
| 19 | int main(int argc, char** argv) { |
| 20 | base::AtExitManager exit_manager; |
| 21 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 22 | scoped_ptr<crypto::RSAPrivateKey> key(crypto::RSAPrivateKey::Create(2048)); |
[email protected] | e354d2c | 2010-07-14 21:38:31 | [diff] [blame] | 23 | |
| 24 | std::vector<uint8> private_key_buf; |
| 25 | key->ExportPrivateKey(&private_key_buf); |
| 26 | std::string private_key_str(private_key_buf.begin(), private_key_buf.end()); |
| 27 | std::string private_key_base64; |
| 28 | base::Base64Encode(private_key_str, &private_key_base64); |
| 29 | printf("%s\n", private_key_base64.c_str()); |
| 30 | |
| 31 | std::vector<uint8> public_key_buf; |
| 32 | key->ExportPublicKey(&public_key_buf); |
| 33 | std::string public_key_str(public_key_buf.begin(), public_key_buf.end()); |
| 34 | std::string public_key_base64; |
| 35 | base::Base64Encode(public_key_str, &public_key_base64); |
| 36 | printf("%s\n", public_key_base64.c_str()); |
| 37 | } |