Home | History | Annotate | Download | only in host
      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
      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"
     16 #include "crypto/rsa_private_key.h"
     17 #include "base/memory/scoped_ptr.h"
     18 
     19 int main(int argc, char** argv) {
     20   base::AtExitManager exit_manager;
     21 
     22   scoped_ptr<crypto::RSAPrivateKey> key(crypto::RSAPrivateKey::Create(2048));
     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 }
     38