Ariel Grabijas
Ariel Grabijas

Reputation: 1512

AES key wrap encryption

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

Answers (3)

Sunny Khatik
Sunny Khatik

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

Duncan Jones
Duncan Jones

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

vcsjones
vcsjones

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

Related Questions