use of org.bouncycastle.crypto.params.KeyParameter in project nem2-sdk-java by nemtech.
the class Ed25519BlockCipher method setupBlockCipher.
private BufferedBlockCipher setupBlockCipher(final byte[] sharedKey, final byte[] ivData, final boolean forEncryption) {
// Setup cipher parameters with key and IV.
final KeyParameter keyParam = new KeyParameter(sharedKey);
final CipherParameters params = new ParametersWithIV(keyParam, ivData);
// Setup AES cipher in CBC mode with PKCS7 padding.
final BlockCipherPadding padding = new PKCS7Padding();
final BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), padding);
cipher.reset();
cipher.init(forEncryption, params);
return cipher;
}
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);
Digest digest = null;
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();
}
use of org.bouncycastle.crypto.params.KeyParameter in project web3sdk by FISCO-BCOS.
the class Wallet method generateAes128CtrDerivedKey.
private static byte[] generateAes128CtrDerivedKey(byte[] password, byte[] salt, int c, String prf) throws CipherException {
if (!prf.equals("hmac-sha256")) {
throw new CipherException("Unsupported prf:" + prf);
}
// Java 8 supports this, but you have to convert the password to a character array, see
// http://stackoverflow.com/a/27928435/3211687
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA256Digest());
gen.init(password, salt, c);
return ((KeyParameter) gen.generateDerivedParameters(256)).getKey();
}
Aggregations