OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "crypto/encryptor.h" | 5 #include "crypto/encryptor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "crypto/symmetric_key.h" | 11 #include "crypto/symmetric_key.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 TEST(EncryptorTest, EncryptDecrypt) { | 14 TEST(EncryptorTest, EncryptDecrypt) { |
15 scoped_ptr<crypto::SymmetricKey> key( | 15 scoped_ptr<crypto::SymmetricKey> key( |
16 crypto::SymmetricKey::DeriveKeyFromPassword( | 16 crypto::SymmetricKey::DeriveKeyFromPassword( |
17 crypto::SymmetricKey::AES, "password", "saltiest", 1000, 256)); | 17 crypto::SymmetricKey::AES, "password", "saltiest", 1000, 256)); |
18 EXPECT_TRUE(NULL != key.get()); | 18 EXPECT_TRUE(NULL != key.get()); |
19 | 19 |
20 crypto::Encryptor encryptor; | 20 crypto::Encryptor encryptor; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 crypto::Encryptor encryptor; | 361 crypto::Encryptor encryptor; |
362 // The IV must be exactly as long a the cipher block size. | 362 // The IV must be exactly as long a the cipher block size. |
363 EXPECT_EQ(16U, iv.size()); | 363 EXPECT_EQ(16U, iv.size()); |
364 EXPECT_TRUE(encryptor.Init(sym_key.get(), crypto::Encryptor::CBC, iv)); | 364 EXPECT_TRUE(encryptor.Init(sym_key.get(), crypto::Encryptor::CBC, iv)); |
365 | 365 |
366 std::string ciphertext; | 366 std::string ciphertext; |
367 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext)); | 367 EXPECT_TRUE(encryptor.Encrypt(plaintext, &ciphertext)); |
368 EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(), | 368 EXPECT_EQ(expected_ciphertext_hex, base::HexEncode(ciphertext.data(), |
369 ciphertext.size())); | 369 ciphertext.size())); |
370 } | 370 } |
OLD | NEW |