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