blob: 218c7ba04ccc3e0d5cb352d5b5eeaccd67a87ca0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/crypto/encryptor.h"
#include <string>
#include "base/crypto/symmetric_key.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(USE_NSS) || defined(OS_MACOSX)
#define MAYBE(name) name
#else
#define MAYBE(name) DISABLED_ ## name
#endif
TEST(EncryptorTest, MAYBE(EncryptDecrypt)) {
scoped_ptr<base::SymmetricKey> key(base::SymmetricKey::DeriveKeyFromPassword(
base::SymmetricKey::AES, "password", "saltiest", 1000, 256));
EXPECT_TRUE(NULL != key.get());
base::Encryptor encryptor;
// The IV must be exactly as long a the cipher block size.
std::string iv("the iv: 16 bytes");
EXPECT_TRUE(encryptor.Init(key.release(), base::Encryptor::CBC, iv));
std::string plaintext("this is the plaintext");
std::string ciphertext;
EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext));
EXPECT_LT(0U, ciphertext.size());
std::string decypted;
EXPECT_TRUE(encryptor.Decrypt(ciphertext, &decypted));
EXPECT_EQ(plaintext, decypted);
}
|