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 #include "crypto/rsa_private_key.h" | 5 #include "crypto/rsa_private_key.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 RSAPrivateKey::RSAPrivateKey() : provider_(NULL), key_(NULL) {} | 128 RSAPrivateKey::RSAPrivateKey() : provider_(NULL), key_(NULL) {} |
129 | 129 |
130 RSAPrivateKey::~RSAPrivateKey() {} | 130 RSAPrivateKey::~RSAPrivateKey() {} |
131 | 131 |
132 bool RSAPrivateKey::InitProvider() { | 132 bool RSAPrivateKey::InitProvider() { |
133 return FALSE != CryptAcquireContext(provider_.receive(), NULL, NULL, | 133 return FALSE != CryptAcquireContext(provider_.receive(), NULL, NULL, |
134 PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); | 134 PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); |
135 } | 135 } |
136 | 136 |
| 137 RSAPrivateKey* RSAPrivateKey::Copy() const { |
| 138 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey()); |
| 139 copy->provider_ = CryptContextAddRef(provider_, NULL, 0); |
| 140 if (!CryptDuplicateKey(key_.get(), NULL, 0, copy->key_.receive())) |
| 141 return NULL; |
| 142 return copy.release(); |
| 143 } |
| 144 |
137 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { | 145 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) { |
138 // Export the key | 146 // Export the key |
139 DWORD blob_length = 0; | 147 DWORD blob_length = 0; |
140 if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, NULL, &blob_length)) { | 148 if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, NULL, &blob_length)) { |
141 NOTREACHED(); | 149 NOTREACHED(); |
142 return false; | 150 return false; |
143 } | 151 } |
144 | 152 |
145 scoped_array<uint8> blob(new uint8[blob_length]); | 153 scoped_array<uint8> blob(new uint8[blob_length]); |
146 if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, blob.get(), &blob_length)) { | 154 if (!CryptExportKey(key_, 0, PRIVATEKEYBLOB, 0, blob.get(), &blob_length)) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 &encoded_length)) { | 228 &encoded_length)) { |
221 NOTREACHED(); | 229 NOTREACHED(); |
222 return false; | 230 return false; |
223 } | 231 } |
224 | 232 |
225 output->assign(encoded.get(), encoded.get() + encoded_length); | 233 output->assign(encoded.get(), encoded.get() + encoded_length); |
226 return true; | 234 return true; |
227 } | 235 } |
228 | 236 |
229 } // namespace crypto | 237 } // namespace crypto |
OLD | NEW |