| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_ENCRYPTOR_ENCRYPTOR_H_ | 5 #ifndef COMPONENTS_ENCRYPTOR_OS_CRYPT_H_ |
| 6 #define COMPONENTS_ENCRYPTOR_ENCRYPTOR_H_ | 6 #define COMPONENTS_ENCRYPTOR_OS_CRYPT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 | 11 |
| 12 // The Encryptor class gives access to simple encryption and decryption of | 12 // The OSCrypt class gives access to simple encryption and decryption of |
| 13 // strings. Note that on Mac, access to the system Keychain is required and | 13 // strings. Note that on Mac, access to the system Keychain is required and |
| 14 // these calls can block the current thread to collect user input. | 14 // these calls can block the current thread to collect user input. |
| 15 class Encryptor { | 15 class OSCrypt { |
| 16 public: | 16 public: |
| 17 // Encrypt a string16. The output (second argument) is | 17 // Encrypt a string16. The output (second argument) is really an array of |
| 18 // really an array of bytes, but we're passing it back | 18 // bytes, but we're passing it back as a std::string. |
| 19 // as a std::string | |
| 20 static bool EncryptString16(const base::string16& plaintext, | 19 static bool EncryptString16(const base::string16& plaintext, |
| 21 std::string* ciphertext); | 20 std::string* ciphertext); |
| 22 | 21 |
| 23 // Decrypt an array of bytes obtained with EncryptString16 | 22 // Decrypt an array of bytes obtained with EncryptString16 back into a |
| 24 // back into a string16. Note that the input (first argument) | 23 // string16. Note that the input (first argument) is a std::string, so you |
| 25 // is a std::string, so you need to first get your (binary) | 24 // need to first get your (binary) data into a string. |
| 26 // data into a string. | |
| 27 static bool DecryptString16(const std::string& ciphertext, | 25 static bool DecryptString16(const std::string& ciphertext, |
| 28 base::string16* plaintext); | 26 base::string16* plaintext); |
| 29 | 27 |
| 30 // Encrypt a string. | 28 // Encrypt a string. |
| 31 static bool EncryptString(const std::string& plaintext, | 29 static bool EncryptString(const std::string& plaintext, |
| 32 std::string* ciphertext); | 30 std::string* ciphertext); |
| 33 | 31 |
| 34 // Decrypt an array of bytes obtained with EnctryptString | 32 // Decrypt an array of bytes obtained with EnctryptString back into a string. |
| 35 // back into a string. Note that the input (first argument) | 33 // Note that the input (first argument) is a std::string, so you need to first |
| 36 // is a std::string, so you need to first get your (binary) | 34 // get your (binary) data into a string. |
| 37 // data into a string. | |
| 38 static bool DecryptString(const std::string& ciphertext, | 35 static bool DecryptString(const std::string& ciphertext, |
| 39 std::string* plaintext); | 36 std::string* plaintext); |
| 40 | 37 |
| 41 #if defined(OS_MACOSX) | 38 #if defined(OS_MACOSX) |
| 42 // For unit testing purposes we instruct the Encryptor to use a mock Keychain | 39 // For unit testing purposes we instruct the Encryptor to use a mock Keychain |
| 43 // on the Mac. The default is to use the real Keychain. | 40 // on the Mac. The default is to use the real Keychain. |
| 44 static void UseMockKeychain(bool use_mock); | 41 static void UseMockKeychain(bool use_mock); |
| 45 #endif | 42 #endif |
| 46 | 43 |
| 47 private: | 44 private: |
| 48 DISALLOW_IMPLICIT_CONSTRUCTORS(Encryptor); | 45 DISALLOW_IMPLICIT_CONSTRUCTORS(OSCrypt); |
| 49 }; | 46 }; |
| 50 | 47 |
| 51 #endif // COMPONENTS_ENCRYPTOR_ENCRYPTOR_H_ | 48 #endif // COMPONENTS_ENCRYPTOR_OS_CRYPT_H_ |
| OLD | NEW |