blob: 91027561008dac2facb4605af310b8529ec9b099 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]e354d2c2010-07-14 21:38:312// 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]4b559b4d2011-04-14 17:37:1416#include "crypto/rsa_private_key.h"
[email protected]3b63f8f42011-03-28 01:54:1517#include "base/memory/scoped_ptr.h"
[email protected]e354d2c2010-07-14 21:38:3118
19int main(int argc, char** argv) {
20 base::AtExitManager exit_manager;
21
[email protected]4b559b4d2011-04-14 17:37:1422 scoped_ptr<crypto::RSAPrivateKey> key(crypto::RSAPrivateKey::Create(2048));
[email protected]e354d2c2010-07-14 21:38:3123
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}