| 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 #include "base/crypto/encryptor.h" | 5 #include "base/crypto/encryptor.h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/crypto/symmetric_key.h" | 10 #include "base/crypto/symmetric_key.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 ciphertext_len - op_len); | 78 ciphertext_len - op_len); |
| 79 if (SECSuccess != rv) | 79 if (SECSuccess != rv) |
| 80 return false; | 80 return false; |
| 81 | 81 |
| 82 ciphertext->assign(reinterpret_cast<char *>(&buffer[0]), | 82 ciphertext->assign(reinterpret_cast<char *>(&buffer[0]), |
| 83 op_len + digest_len); | 83 op_len + digest_len); |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool Encryptor::Decrypt(const std::string& ciphertext, std::string* plaintext) { | 87 bool Encryptor::Decrypt(const std::string& ciphertext, std::string* plaintext) { |
| 88 if (ciphertext.size() == 0) | 88 if (ciphertext.empty()) |
| 89 return false; | 89 return false; |
| 90 | 90 |
| 91 ScopedPK11Context context(PK11_CreateContextBySymKey(CKM_AES_CBC_PAD, | 91 ScopedPK11Context context(PK11_CreateContextBySymKey(CKM_AES_CBC_PAD, |
| 92 CKA_DECRYPT, | 92 CKA_DECRYPT, |
| 93 key_->key(), | 93 key_->key(), |
| 94 param_.get())); | 94 param_.get())); |
| 95 if (!context.get()) | 95 if (!context.get()) |
| 96 return false; | 96 return false; |
| 97 | 97 |
| 98 size_t plaintext_len = ciphertext.size(); | 98 size_t plaintext_len = ciphertext.size(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 116 plaintext_len - op_len); | 116 plaintext_len - op_len); |
| 117 if (SECSuccess != rv) | 117 if (SECSuccess != rv) |
| 118 return false; | 118 return false; |
| 119 | 119 |
| 120 plaintext->assign(reinterpret_cast<char *>(&buffer[0]), | 120 plaintext->assign(reinterpret_cast<char *>(&buffer[0]), |
| 121 op_len + digest_len); | 121 op_len + digest_len); |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace base | 125 } // namespace base |
| OLD | NEW |