CipherWrapThreadpublic class CipherWrapThread extends CipherThread
Constructors Summary |
---|
CipherWrapThread(String name, int[] keys, String[] modes, String[] paddings)
super(name, keys, modes, paddings);
|
Methods Summary |
---|
public void | crypt()
KeyGenerator kg = KeyGenerator.getInstance(getAlgName().replace("Wrap", ""));
kg.init(getKeyLength(), new SecureRandom());
Key key = kg.generateKey();
// ignore mode and padding
Cipher cip = Cipher.getInstance(getAlgName());
cip.init(Cipher.WRAP_MODE, key);
byte[] output = cip.wrap(key);
cip.init(Cipher.UNWRAP_MODE, key);
Key decrypted = cip.unwrap(output, getAlgName(), Cipher.SECRET_KEY);
checkEncodedData(key.getFormat().getBytes(), decrypted.getFormat().getBytes());
checkEncodedData(key.getEncoded(), decrypted.getEncoded());
|
|