| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "base/crypto/encryptor.h" | 5 #include "base/crypto/encryptor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/crypto/symmetric_key.h" | 9 #include "base/crypto/symmetric_key.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.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<base::SymmetricKey> key(base::SymmetricKey::DeriveKeyFromPassword( | 15 scoped_ptr<base::SymmetricKey> key(base::SymmetricKey::DeriveKeyFromPassword( |
| 16 base::SymmetricKey::AES, "password", "saltiest", 1000, 256)); | 16 base::SymmetricKey::AES, "password", "saltiest", 1000, 256)); |
| 17 EXPECT_TRUE(NULL != key.get()); | 17 EXPECT_TRUE(NULL != key.get()); |
| 18 | 18 |
| 19 base::Encryptor encryptor; | 19 base::Encryptor encryptor; |
| 20 // The IV must be exactly as long as the cipher block size. | 20 // The IV must be exactly as long as the cipher block size. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 base::Encryptor encryptor; | 224 base::Encryptor encryptor; |
| 225 // The IV must be exactly as long a the cipher block size. | 225 // The IV must be exactly as long a the cipher block size. |
| 226 EXPECT_EQ(16U, iv.size()); | 226 EXPECT_EQ(16U, iv.size()); |
| 227 EXPECT_TRUE(encryptor.Init(sym_key.get(), base::Encryptor::CBC, iv)); | 227 EXPECT_TRUE(encryptor.Init(sym_key.get(), base::Encryptor::CBC, iv)); |
| 228 | 228 |
| 229 std::string decrypted; | 229 std::string decrypted; |
| 230 EXPECT_FALSE(encryptor.Decrypt("", &decrypted)); | 230 EXPECT_FALSE(encryptor.Decrypt("", &decrypted)); |
| 231 EXPECT_EQ("", decrypted); | 231 EXPECT_EQ("", decrypted); |
| 232 } | 232 } |
| OLD | NEW |