use of org.bouncycastle.crypto.params.KeyParameter in project Skein3Fish by wernerd.
the class SkeinMac method init.
public void init(CipherParameters params) throws IllegalArgumentException {
ParametersForSkein p = (ParametersForSkein) params;
KeyParameter kp = (KeyParameter) (p.getParameters());
skein = new Skein(p.getStateSize(), p.getMacSize(), 0, kp.getKey());
Xsave = skein.getState();
}
use of org.bouncycastle.crypto.params.KeyParameter in project elastic-core-maven by OrdinaryDude.
the class Crypto method aesGCMDecrypt.
public static byte[] aesGCMDecrypt(byte[] ivCiphertext, byte[] key) {
try {
if (ivCiphertext.length < 16) {
throw new InvalidCipherTextException("invalid ivCiphertext length");
}
byte[] iv = Arrays.copyOfRange(ivCiphertext, 0, 16);
byte[] ciphertext = Arrays.copyOfRange(ivCiphertext, 16, ivCiphertext.length);
GCMBlockCipher aes = new GCMBlockCipher(new AESEngine());
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(false, ivAndKey);
byte[] output = new byte[aes.getOutputSize(ciphertext.length)];
int plaintextLength = aes.processBytes(ciphertext, 0, ciphertext.length, output, 0);
plaintextLength += aes.doFinal(output, plaintextLength);
byte[] result = new byte[plaintextLength];
System.arraycopy(output, 0, result, 0, result.length);
return result;
} catch (InvalidCipherTextException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.bouncycastle.crypto.params.KeyParameter in project elastic-core-maven by OrdinaryDude.
the class Crypto method aesEncrypt.
public static byte[] aesEncrypt(byte[] plaintext, byte[] key) {
try {
byte[] iv = new byte[16];
secureRandom.get().nextBytes(iv);
PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()));
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(true, ivAndKey);
byte[] output = new byte[aes.getOutputSize(plaintext.length)];
int ciphertextLength = aes.processBytes(plaintext, 0, plaintext.length, output, 0);
ciphertextLength += aes.doFinal(output, ciphertextLength);
byte[] result = new byte[iv.length + ciphertextLength];
System.arraycopy(iv, 0, result, 0, iv.length);
System.arraycopy(output, 0, result, iv.length, ciphertextLength);
return result;
} catch (InvalidCipherTextException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.bouncycastle.crypto.params.KeyParameter in project elastic-core-maven by OrdinaryDude.
the class Crypto method aesGCMEncrypt.
public static byte[] aesGCMEncrypt(byte[] plaintext, byte[] key) {
try {
byte[] iv = new byte[16];
secureRandom.get().nextBytes(iv);
GCMBlockCipher aes = new GCMBlockCipher(new AESEngine());
CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
aes.init(true, ivAndKey);
byte[] output = new byte[aes.getOutputSize(plaintext.length)];
int ciphertextLength = aes.processBytes(plaintext, 0, plaintext.length, output, 0);
ciphertextLength += aes.doFinal(output, ciphertextLength);
byte[] result = new byte[iv.length + ciphertextLength];
System.arraycopy(iv, 0, result, 0, iv.length);
System.arraycopy(output, 0, result, iv.length, ciphertextLength);
return result;
} catch (InvalidCipherTextException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.bouncycastle.crypto.params.KeyParameter in project cxf by apache.
the class PbesHmacAesWrapKeyEncryptionAlgorithm method createDerivedKey.
static byte[] createDerivedKey(String keyAlgoJwt, int keySize, byte[] password, byte[] saltInput, int pbesCount) {
byte[] saltValue = createSaltValue(keyAlgoJwt, saltInput);
final Digest digest;
int macSigSize = PBES_HMAC_MAP.get(keyAlgoJwt);
if (macSigSize == 256) {
digest = new SHA256Digest();
} else if (macSigSize == 384) {
digest = new SHA384Digest();
} else {
digest = new SHA512Digest();
}
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
gen.init(password, saltValue, pbesCount);
return ((KeyParameter) gen.generateDerivedParameters(keySize * 8)).getKey();
}
Aggregations