blob: 5267549dd048fc087961058a4fb0b4322728717a [file] [log] [blame]
[email protected]39422e32010-03-25 19:13:001// 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 BASE_CRYPTO_ENCRYPTOR_H_
6#define BASE_CRYPTO_ENCRYPTOR_H_
7
8#include <string>
9
[email protected]692033a2010-04-09 18:40:5010#include "build/build_config.h"
11
12#if defined(USE_NSS)
13#include "base/crypto/scoped_nss_types.h"
14#elif defined(OS_WIN)
15#include "base/crypto/scoped_capi_types.h"
16#endif
[email protected]39422e32010-03-25 19:13:0017
18namespace base {
19
[email protected]692033a2010-04-09 18:40:5020class SymmetricKey;
21
[email protected]39422e32010-03-25 19:13:0022class Encryptor {
23 public:
24 enum Mode {
25 CBC
26 };
[email protected]1b47ce22010-03-31 16:18:3027 Encryptor();
28 virtual ~Encryptor();
[email protected]39422e32010-03-25 19:13:0029
[email protected]1b47ce22010-03-31 16:18:3030 // Initializes the encryptor using |key| and |iv|. Returns false if either the
31 // key or the initialization vector cannot be used.
[email protected]39422e32010-03-25 19:13:0032 bool Init(SymmetricKey* key, Mode mode, const std::string& iv);
33
34 // Encrypts |plaintext| into |ciphertext|.
35 bool Encrypt(const std::string& plaintext, std::string* ciphertext);
36
37 // Decrypts |ciphertext| into |plaintext|.
38 bool Decrypt(const std::string& ciphertext, std::string* plaintext);
39
40 // TODO(albertb): Support streaming encryption.
41
42 private:
[email protected]1b47ce22010-03-31 16:18:3043 SymmetricKey* key_;
[email protected]39422e32010-03-25 19:13:0044 Mode mode_;
[email protected]39422e32010-03-25 19:13:0045
46#if defined(USE_NSS)
47 ScopedPK11Slot slot_;
48 ScopedSECItem param_;
[email protected]108118232010-03-29 18:22:2449#elif defined(OS_MACOSX)
50 bool Crypt(int /*CCOperation*/ op,
51 const std::string& input,
52 std::string* output);
53
54 std::string iv_;
[email protected]692033a2010-04-09 18:40:5055#elif defined(OS_WIN)
56 ScopedHCRYPTKEY capi_key_;
57 DWORD block_size_;
[email protected]39422e32010-03-25 19:13:0058#endif
59};
60
61} // namespace base
62
63#endif // BASE_CRYPTO_ENCRYPTOR_H_