| 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 #ifndef CRYPTO_ENCRYPTOR_H_ | 5 #ifndef CRYPTO_ENCRYPTOR_H_ |
| 6 #define CRYPTO_ENCRYPTOR_H_ | 6 #define CRYPTO_ENCRYPTOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 | 12 |
| 13 #if defined(USE_NSS) | 13 #if defined(USE_NSS) |
| 14 #include "crypto/scoped_nss_types.h" | 14 #include "crypto/scoped_nss_types.h" |
| 15 #elif defined(OS_WIN) | 15 #elif defined(OS_WIN) |
| 16 #include "crypto/scoped_capi_types.h" | 16 #include "crypto/scoped_capi_types.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace crypto { | 19 namespace crypto { |
| 20 | 20 |
| 21 class SymmetricKey; | 21 class SymmetricKey; |
| 22 | 22 |
| 23 class Encryptor { | 23 class Encryptor { |
| 24 public: | 24 public: |
| 25 enum Mode { | 25 enum Mode { |
| 26 CBC | 26 CBC, |
| 27 ECB, |
| 27 }; | 28 }; |
| 28 Encryptor(); | 29 Encryptor(); |
| 29 virtual ~Encryptor(); | 30 virtual ~Encryptor(); |
| 30 | 31 |
| 31 // Initializes the encryptor using |key| and |iv|. Returns false if either the | 32 // Initializes the encryptor using |key| and |iv|. Returns false if either the |
| 32 // key or the initialization vector cannot be used. | 33 // key or the initialization vector cannot be used. |
| 33 bool Init(SymmetricKey* key, Mode mode, const std::string& iv); | 34 bool Init(SymmetricKey* key, Mode mode, const std::string& iv); |
| 34 | 35 |
| 35 // Encrypts |plaintext| into |ciphertext|. | 36 // Encrypts |plaintext| into |ciphertext|. |
| 36 bool Encrypt(const std::string& plaintext, std::string* ciphertext); | 37 bool Encrypt(const std::string& plaintext, std::string* ciphertext); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 60 std::string iv_; | 61 std::string iv_; |
| 61 #elif defined(OS_WIN) | 62 #elif defined(OS_WIN) |
| 62 ScopedHCRYPTKEY capi_key_; | 63 ScopedHCRYPTKEY capi_key_; |
| 63 DWORD block_size_; | 64 DWORD block_size_; |
| 64 #endif | 65 #endif |
| 65 }; | 66 }; |
| 66 | 67 |
| 67 } // namespace crypto | 68 } // namespace crypto |
| 68 | 69 |
| 69 #endif // CRYPTO_ENCRYPTOR_H_ | 70 #endif // CRYPTO_ENCRYPTOR_H_ |
| OLD | NEW |