21
21
22
22
import javax .crypto .Cipher ;
23
23
import javax .crypto .SecretKey ;
24
+ import javax .crypto .spec .SecretKeySpec ;
24
25
import java .nio .charset .Charset ;
25
26
import java .nio .charset .StandardCharsets ;
26
27
import java .security .GeneralSecurityException ;
@@ -80,7 +81,7 @@ abstract Cipher buildUnwrappingCipher(Key key, byte[] extraInfo, int offset,
80
81
* during encryption and decryption to provide additional authenticated data (AAD).
81
82
* @return The encrypted data key.
82
83
*/
83
- public EncryptedDataKey encryptKey (final Key key , final String keyName ,
84
+ public EncryptedDataKey encryptKey (final SecretKey key , final String keyName ,
84
85
final Map <String , String > encryptionContext ) {
85
86
86
87
final byte [] keyBytes = key .getEncoded ();
@@ -112,7 +113,7 @@ public EncryptedDataKey encryptKey(final Key key, final String keyName,
112
113
* @return The decrypted key.
113
114
* @throws GeneralSecurityException If a problem occurred decrypting the key.
114
115
*/
115
- public KeyBlob decryptKey (final CryptoAlgorithm algorithm , final EncryptedDataKey edk , final String keyName ,
116
+ public SecretKey decryptKey (final CryptoAlgorithm algorithm , final EncryptedDataKey edk , final String keyName ,
116
117
final Map <String , String > encryptionContext ) throws GeneralSecurityException {
117
118
final byte [] keyNameBytes = keyName .getBytes (KEY_NAME_ENCODING );
118
119
@@ -124,7 +125,7 @@ public KeyBlob decryptKey(final CryptoAlgorithm algorithm, final EncryptedDataKe
124
125
return null ;
125
126
}
126
127
127
- return new KeyBlob ( edk . getProviderId (), edk . getProviderInformation (), rawKey );
128
+ return new SecretKeySpec ( rawKey , algorithm . getDataKeyAlgo () );
128
129
}
129
130
130
131
static class WrappingData {
0 commit comments