use of java.security.InvalidKeyException in project XobotOS by xamarin.
the class X509CertificateObject method verify.
public final void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
Signature signature;
String sigName = X509SignatureUtil.getSignatureName(c.getSignatureAlgorithm());
try {
signature = Signature.getInstance(sigName, BouncyCastleProvider.PROVIDER_NAME);
} catch (Exception e) {
signature = Signature.getInstance(sigName);
}
checkSignature(key, signature);
}
use of java.security.InvalidKeyException in project XobotOS by xamarin.
the class ECUtil method generatePrivateKeyParameter.
public static AsymmetricKeyParameter generatePrivateKeyParameter(PrivateKey key) throws InvalidKeyException {
if (key instanceof ECPrivateKey) {
ECPrivateKey k = (ECPrivateKey) key;
ECParameterSpec s = k.getParameters();
if (s == null) {
s = ProviderUtil.getEcImplicitlyCa();
}
return new ECPrivateKeyParameters(k.getD(), new ECDomainParameters(s.getCurve(), s.getG(), s.getN(), s.getH(), s.getSeed()));
}
throw new InvalidKeyException("can't identify EC private key.");
}
use of java.security.InvalidKeyException in project XobotOS by xamarin.
the class Signature method engineInitSign.
protected void engineInitSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException {
CipherParameters param;
if (privateKey instanceof ECKey) {
param = ECUtil.generatePrivateKeyParameter(privateKey);
} else {
throw new InvalidKeyException("can't recognise key type in ECDSA based signer");
}
digest.reset();
if (random != null) {
signer.init(true, new ParametersWithRandom(param, random));
} else {
signer.init(true, param);
}
}
use of java.security.InvalidKeyException in project otter by alibaba.
the class AESUtils method encrypt.
/**
* 加密byte数据
*
* @param plainData
* @return
* @throws AESException
*/
public byte[] encrypt(byte[] plainData) throws AESException {
try {
SecretKeySpec skeySpec = new SecretKeySpec(secretKey, ENCRYPTION_ALGORITHM);
// Instantiate the cipher
Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
return cipher.doFinal(plainData);
} catch (NoSuchAlgorithmException e) {
throw new AESException(e);
} catch (NoSuchPaddingException e) {
throw new AESException(e);
} catch (InvalidKeyException e) {
throw new AESException(e);
} catch (IllegalBlockSizeException e) {
throw new AESException(e);
} catch (BadPaddingException e) {
throw new AESException(e);
}
}
use of java.security.InvalidKeyException in project camel by apache.
the class RSAKeyPairIdentity method getSignature.
@Override
public byte[] getSignature(byte[] data) {
PrivateKey prvKey = keyPair.getPrivate();
Signature sig;
try {
sig = Signature.getInstance("SHA1withRSA");
sig.initSign(prvKey);
sig.update(data);
byte[] sshRsa = ALGORITHM_TYPE.getBytes();
byte[] signature = sig.sign();
byte[] result = new byte[sshRsa.length + 4 + signature.length + 4];
int index = 0;
byte[] intAsByteArray = ByteBuffer.allocate(4).putInt(sshRsa.length).array();
System.arraycopy(intAsByteArray, 0, result, index, 4);
index += 4;
System.arraycopy(sshRsa, 0, result, index, sshRsa.length);
index += sshRsa.length;
intAsByteArray = ByteBuffer.allocate(4).putInt(signature.length).array();
System.arraycopy(intAsByteArray, 0, result, index, 4);
index += 4;
System.arraycopy(signature, 0, result, index, signature.length);
return result;
} catch (NoSuchAlgorithmException e) {
log.error("Cannot sign", e);
} catch (InvalidKeyException e) {
log.error("Cannot sign", e);
} catch (SignatureException e) {
log.error("Cannot sign", e);
}
return null;
}
Aggregations