Reputation: 1512
I need crypto-algorithm AES in key wrap mode. Is there some open-source library or implementation that could be helpful?
It is important, that it must be key wrap mode.
Upvotes: 6
Views: 7154
Reputation: 17
yes there is a library available named Bouncy Castle
you can use that library for wrapping your data encryption key using AES algorithm in WRAP_MODE
,here below code snippet might help you.
public static byte[] wrapKey(SecretKey key, SecretKey keyToWrap) throws GeneralSecurityException {
Cipher cipher = Cipher.getInstance("AESKW", "BCFIPS");
cipher.init(Cipher.WRAP_MODE, key);
return cipher.wrap(keyToWrap);
}
public static SecretKey unwrapKey(SecretKey key, byte[] wrappedKey) throws GeneralSecurityException {
Cipher cipher = Cipher.getInstance("AESKW", "BCFIPS");
cipher.init(Cipher.UNWRAP_MODE, key);
return (SecretKey) cipher.unwrap(wrappedKey, "AES", Cipher.SECRET_KEY);
}
Upvotes: 1
Reputation: 69389
The standard SunJCE provider offers an implementation of RFC 3394. Just use the algorithm AESWrap
:
Cipher c = Cipher.getInstance("AESWrap", "SunJCE");
c.init(Cipher.WRAP_MODE, secretKey);
byte[] result = c.wrap(someKey);
Upvotes: 11
Reputation: 141678
BouncyCastle supports key wrapping in AES with the AESWrapEngine
.
You can look at this StackOverflow post to see more examples of BouncyCastle. The only difference is you will specify the AESWrapEngine
instead of the AESEngine
.
Upvotes: 3