Added RSA key generator for register_host.py
TEST=None
BUG=None
Review URL: http://codereview.chromium.org/2958001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52406 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/remoting/host/keygen_main.cc b/remoting/host/keygen_main.cc
new file mode 100644
index 0000000..88f363c
--- /dev/null
+++ b/remoting/host/keygen_main.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This is a tool used by register_host.py to generate RSA keypair. It just
+// generates new keys and prints them on stdout.
+//
+// This code will need to be integrated with the host registration UI.
+
+#include <stdio.h>
+
+#include <vector>
+
+#include "base/at_exit.h"
+#include "base/base64.h"
+#include "base/crypto/rsa_private_key.h"
+#include "base/scoped_ptr.h"
+
+int main(int argc, char** argv) {
+ base::AtExitManager exit_manager;
+
+ scoped_ptr<base::RSAPrivateKey> key(base::RSAPrivateKey::Create(2048));
+
+ std::vector<uint8> private_key_buf;
+ key->ExportPrivateKey(&private_key_buf);
+ std::string private_key_str(private_key_buf.begin(), private_key_buf.end());
+ std::string private_key_base64;
+ base::Base64Encode(private_key_str, &private_key_base64);
+ printf("%s\n", private_key_base64.c_str());
+
+ std::vector<uint8> public_key_buf;
+ key->ExportPublicKey(&public_key_buf);
+ std::string public_key_str(public_key_buf.begin(), public_key_buf.end());
+ std::string public_key_base64;
+ base::Base64Encode(public_key_str, &public_key_base64);
+ printf("%s\n", public_key_base64.c_str());
+}