| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // NOTE: this file is Winodws specific. | 5 // NOTE: this file is Winodws specific. |
| 6 | 6 |
| 7 #include "chrome/browser/sync/util/data_encryption.h" | 7 #include "sync/util/data_encryption_win.h" |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <wincrypt.h> | 10 #include <wincrypt.h> |
| 11 | 11 |
| 12 #include <cstddef> | 12 #include <cstddef> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 | 17 |
| 18 #pragma comment(lib, "crypt32.lib") |
| 19 |
| 20 // TODO(akalin): Merge this with similar code in |
| 21 // chrome/browser/password_manager/encryptor_win.cc. Preferably, all |
| 22 // this stuff would live in crypto/. |
| 23 |
| 18 using std::string; | 24 using std::string; |
| 19 using std::vector; | 25 using std::vector; |
| 20 | 26 |
| 21 vector<uint8> EncryptData(const string& data) { | 27 vector<uint8> EncryptData(const string& data) { |
| 22 DATA_BLOB unencrypted_data = { 0 }; | 28 DATA_BLOB unencrypted_data = { 0 }; |
| 23 unencrypted_data.pbData = (BYTE*)(data.data()); | 29 unencrypted_data.pbData = (BYTE*)(data.data()); |
| 24 unencrypted_data.cbData = data.size(); | 30 unencrypted_data.cbData = data.size(); |
| 25 DATA_BLOB encrypted_data = { 0 }; | 31 DATA_BLOB encrypted_data = { 0 }; |
| 26 | 32 |
| 27 if (!CryptProtectData(&unencrypted_data, L"", NULL, NULL, NULL, 0, | 33 if (!CryptProtectData(&unencrypted_data, L"", NULL, NULL, NULL, 0, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 &decrypted_data)) { | 51 &decrypted_data)) { |
| 46 LOG(ERROR) << "Decryption fails: "; | 52 LOG(ERROR) << "Decryption fails: "; |
| 47 return false; | 53 return false; |
| 48 } else { | 54 } else { |
| 49 out_data->assign(reinterpret_cast<const char*>(decrypted_data.pbData), | 55 out_data->assign(reinterpret_cast<const char*>(decrypted_data.pbData), |
| 50 decrypted_data.cbData); | 56 decrypted_data.cbData); |
| 51 LocalFree(decrypted_data.pbData); | 57 LocalFree(decrypted_data.pbData); |
| 52 return true; | 58 return true; |
| 53 } | 59 } |
| 54 } | 60 } |
| OLD | NEW |