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 #ifndef CRYPTO_SYMMETRIC_KEY_H_ | 5 #ifndef CRYPTO_SYMMETRIC_KEY_H_ |
6 #define CRYPTO_SYMMETRIC_KEY_H_ | 6 #define CRYPTO_SYMMETRIC_KEY_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // SymmetricKey. | 43 // SymmetricKey. |
44 static std::unique_ptr<SymmetricKey> DeriveKeyFromPassword( | 44 static std::unique_ptr<SymmetricKey> DeriveKeyFromPassword( |
45 Algorithm algorithm, | 45 Algorithm algorithm, |
46 const std::string& password, | 46 const std::string& password, |
47 const std::string& salt, | 47 const std::string& salt, |
48 size_t iterations, | 48 size_t iterations, |
49 size_t key_size_in_bits); | 49 size_t key_size_in_bits); |
50 | 50 |
51 // Imports an array of key bytes in |raw_key|. This key may have been | 51 // Imports an array of key bytes in |raw_key|. This key may have been |
52 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with | 52 // generated by GenerateRandomKey or DeriveKeyFromPassword and exported with |
53 // GetRawKey, or via another compatible method. The key must be of suitable | 53 // key(). The key must be of suitable size for use with |algorithm|. |
54 // size for use with |algorithm|. The caller owns the returned SymmetricKey. | 54 // The caller owns the returned SymmetricKey. |
55 static std::unique_ptr<SymmetricKey> Import(Algorithm algorithm, | 55 static std::unique_ptr<SymmetricKey> Import(Algorithm algorithm, |
56 const std::string& raw_key); | 56 const std::string& raw_key); |
57 | 57 |
| 58 // Returns the raw platform specific key data. |
58 const std::string& key() const { return key_; } | 59 const std::string& key() const { return key_; } |
59 | 60 |
60 // Extracts the raw key from the platform specific data. | |
61 // Warning: |raw_key| holds the raw key as bytes and thus must be handled | |
62 // carefully. | |
63 bool GetRawKey(std::string* raw_key) const; | |
64 | |
65 private: | 61 private: |
66 SymmetricKey(); | 62 SymmetricKey(); |
67 | 63 |
68 std::string key_; | 64 std::string key_; |
69 | 65 |
70 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); | 66 DISALLOW_COPY_AND_ASSIGN(SymmetricKey); |
71 }; | 67 }; |
72 | 68 |
73 } // namespace crypto | 69 } // namespace crypto |
74 | 70 |
75 #endif // CRYPTO_SYMMETRIC_KEY_H_ | 71 #endif // CRYPTO_SYMMETRIC_KEY_H_ |
OLD | NEW |