use of java.security.spec.InvalidParameterSpecException in project jdk8u_jdk by JetBrains.
the class Cipher method checkCryptoPerm.
private void checkCryptoPerm(CipherSpi checkSpi, Key key, AlgorithmParameters params) throws InvalidKeyException, InvalidAlgorithmParameterException {
if (cryptoPerm == CryptoAllPermission.INSTANCE) {
return;
}
// Convert the specified parameters into specs and then delegate.
AlgorithmParameterSpec pSpec;
try {
pSpec = getAlgorithmParameterSpec(params);
} catch (InvalidParameterSpecException ipse) {
throw new InvalidAlgorithmParameterException("Failed to retrieve algorithm parameter specification");
}
checkCryptoPerm(checkSpi, key, pSpec);
}
use of java.security.spec.InvalidParameterSpecException in project metrics by dropwizard.
the class PacketWriter method encrypt.
private static EncryptionResult encrypt(byte[] password, ByteBuffer input) {
final Cipher cipher;
try {
cipher = Cipher.getInstance(AES_CYPHER);
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(sha256(password), AES));
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) {
throw new RuntimeException(e);
}
final byte[] iv;
try {
iv = cipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV();
} catch (InvalidParameterSpecException e) {
throw new RuntimeException(e);
}
if (iv.length != IV_LENGTH) {
throw new IllegalStateException("Bad initialization vector");
}
final ByteBuffer output = ByteBuffer.allocate(input.remaining() * 2);
try {
cipher.doFinal(input, output);
} catch (ShortBufferException | IllegalBlockSizeException | BadPaddingException e) {
throw new RuntimeException(e);
}
return new EncryptionResult(iv, (ByteBuffer) output.flip());
}
use of java.security.spec.InvalidParameterSpecException in project Bytecoder by mirkosertic.
the class GCMParameters method engineInit.
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
if (!(paramSpec instanceof GCMParameterSpec)) {
throw new InvalidParameterSpecException("Inappropriate parameter specification");
}
GCMParameterSpec gps = (GCMParameterSpec) paramSpec;
// need to convert from bits to bytes for ASN.1 encoding
this.tLen = gps.getTLen() / 8;
this.iv = gps.getIV();
}
use of java.security.spec.InvalidParameterSpecException in project Bytecoder by mirkosertic.
the class RC2Parameters method engineInit.
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
if (!(paramSpec instanceof RC2ParameterSpec)) {
throw new InvalidParameterSpecException("Inappropriate parameter specification");
}
RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;
// check effective key size (a value of 0 means it is unspecified)
effectiveKeySize = rps.getEffectiveKeyBits();
if (effectiveKeySize != 0) {
if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
throw new InvalidParameterSpecException("RC2 effective key " + "size must be between 1 and 1024 bits");
}
if (effectiveKeySize < 256) {
version = EKB_TABLE[effectiveKeySize];
} else {
version = effectiveKeySize;
}
}
this.iv = rps.getIV();
}
use of java.security.spec.InvalidParameterSpecException in project Bytecoder by mirkosertic.
the class DSAParameterGenerator method engineGenerateParameters.
/**
* Generates the parameters.
*
* @return the new AlgorithmParameters object
*/
@Override
protected AlgorithmParameters engineGenerateParameters() {
AlgorithmParameters algParams = null;
try {
if (this.random == null) {
this.random = new SecureRandom();
}
if (valueL == -1) {
try {
engineInit(DEFAULTS, this.random);
} catch (InvalidAlgorithmParameterException iape) {
// should never happen
}
}
BigInteger[] pAndQ = generatePandQ(this.random, valueL, valueN, seedLen);
BigInteger paramP = pAndQ[0];
BigInteger paramQ = pAndQ[1];
BigInteger paramG = generateG(paramP, paramQ);
DSAParameterSpec dsaParamSpec = new DSAParameterSpec(paramP, paramQ, paramG);
algParams = AlgorithmParameters.getInstance("DSA", "SUN");
algParams.init(dsaParamSpec);
} catch (InvalidParameterSpecException e) {
// this should never happen
throw new RuntimeException(e.getMessage());
} catch (NoSuchAlgorithmException e) {
// this should never happen, because we provide it
throw new RuntimeException(e.getMessage());
} catch (NoSuchProviderException e) {
// this should never happen, because we provide it
throw new RuntimeException(e.getMessage());
}
return algParams;
}
Aggregations