Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: base/crypto/encryptor_win.cc

Issue 4777001: Implements encryptor_openssl.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linux & win Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/crypto/encryptor_unittest.cc ('k') | base/crypto/symmetric_key.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/crypto/encryptor.h" 5 #include "base/crypto/encryptor.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/crypto/symmetric_key.h" 9 #include "base/crypto/symmetric_key.h"
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 &data_len, total_len); 86 &data_len, total_len);
87 if (!ok) 87 if (!ok)
88 return false; 88 return false;
89 89
90 ciphertext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); 90 ciphertext->assign(reinterpret_cast<char*>(&tmp[0]), data_len);
91 return true; 91 return true;
92 } 92 }
93 93
94 bool Encryptor::Decrypt(const std::string& ciphertext, std::string* plaintext) { 94 bool Encryptor::Decrypt(const std::string& ciphertext, std::string* plaintext) {
95 DWORD data_len = ciphertext.size(); 95 DWORD data_len = ciphertext.size();
96 if (data_len == 0)
97 return false;
96 98
97 std::vector<BYTE> tmp(data_len); 99 std::vector<BYTE> tmp(data_len);
98 memcpy(&tmp[0], ciphertext.data(), data_len); 100 memcpy(&tmp[0], ciphertext.data(), data_len);
99 101
100 BOOL ok = CryptDecrypt(capi_key_.get(), NULL, TRUE, 0, &tmp[0], &data_len); 102 BOOL ok = CryptDecrypt(capi_key_.get(), NULL, TRUE, 0, &tmp[0], &data_len);
101 if (!ok) 103 if (!ok)
102 return false; 104 return false;
103 105
104 DCHECK_GT(tmp.size(), data_len); 106 DCHECK_GT(tmp.size(), data_len);
105 107
106 plaintext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); 108 plaintext->assign(reinterpret_cast<char*>(&tmp[0]), data_len);
107 return true; 109 return true;
108 } 110 }
109 111
110 } // namespace base 112 } // namespace base
OLDNEW
« no previous file with comments | « base/crypto/encryptor_unittest.cc ('k') | base/crypto/symmetric_key.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698