5

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.

Ariel Grabijas
  • 1,472
  • 5
  • 25
  • 45

3 Answers3

9

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);
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
2

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.

Community
  • 1
  • 1
vcsjones
  • 138,677
  • 31
  • 291
  • 286
0

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);
    }