use of org.bouncycastle.crypto.CipherParameters in project XobotOS by xamarin.
the class JDKDigestSignature method engineInitVerify.
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
if (!(publicKey instanceof RSAPublicKey)) {
throw new InvalidKeyException("Supplied key (" + getType(publicKey) + ") is not a RSAPublicKey instance");
}
CipherParameters param = RSAUtil.generatePublicKeyParameter((RSAPublicKey) publicKey);
digest.reset();
cipher.init(false, param);
}
use of org.bouncycastle.crypto.CipherParameters in project XobotOS by xamarin.
the class WrapCipherSpi method engineInit.
protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
CipherParameters param;
if (key instanceof JCEPBEKey) {
JCEPBEKey k = (JCEPBEKey) key;
if (params instanceof PBEParameterSpec) {
param = PBE.Util.makePBEParameters(k, params, wrapEngine.getAlgorithmName());
} else if (k.getParam() != null) {
param = k.getParam();
} else {
throw new InvalidAlgorithmParameterException("PBE requires PBE parameters to be set.");
}
} else {
param = new KeyParameter(key.getEncoded());
}
if (params instanceof javax.crypto.spec.IvParameterSpec) {
IvParameterSpec iv = (IvParameterSpec) params;
param = new ParametersWithIV(param, iv.getIV());
}
if (param instanceof KeyParameter && ivSize != 0) {
iv = new byte[ivSize];
random.nextBytes(iv);
param = new ParametersWithIV(param, iv);
}
switch(opmode) {
case Cipher.WRAP_MODE:
wrapEngine.init(true, param);
break;
case Cipher.UNWRAP_MODE:
wrapEngine.init(false, param);
break;
case Cipher.ENCRYPT_MODE:
case Cipher.DECRYPT_MODE:
throw new IllegalArgumentException("engine only valid for wrapping");
default:
System.out.println("eeek!");
}
}
use of org.bouncycastle.crypto.CipherParameters in project XobotOS by xamarin.
the class KeyAgreement method engineDoPhase.
protected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException {
if (parameters == null) {
throw new IllegalStateException(kaAlgorithm + " not initialised.");
}
if (!lastPhase) {
throw new IllegalStateException(kaAlgorithm + " can only be between two parties.");
}
CipherParameters pubKey;
// BEGIN android-removed
// if (agreement instanceof ECMQVBasicAgreement)
// {
// if (!(key instanceof MQVPublicKey))
// {
// throw new InvalidKeyException(kaAlgorithm + " key agreement requires "
// + getSimpleName(MQVPublicKey.class) + " for doPhase");
// }
//
// MQVPublicKey mqvPubKey = (MQVPublicKey)key;
// ECPublicKeyParameters staticKey = (ECPublicKeyParameters)
// ECUtil.generatePublicKeyParameter(mqvPubKey.getStaticKey());
// ECPublicKeyParameters ephemKey = (ECPublicKeyParameters)
// ECUtil.generatePublicKeyParameter(mqvPubKey.getEphemeralKey());
//
// pubKey = new MQVPublicParameters(staticKey, ephemKey);
//
// // TODO Validate that all the keys are using the same parameters?
// }
// else
// END android-removed
{
if (!(key instanceof ECPublicKey)) {
throw new InvalidKeyException(kaAlgorithm + " key agreement requires " + getSimpleName(ECPublicKey.class) + " for doPhase");
}
pubKey = ECUtil.generatePublicKeyParameter((PublicKey) key);
// TODO Validate that all the keys are using the same parameters?
}
result = agreement.calculateAgreement(pubKey);
return null;
}
use of org.bouncycastle.crypto.CipherParameters in project XobotOS by xamarin.
the class Signature method engineInitVerify.
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
CipherParameters param;
if (publicKey instanceof ECPublicKey) {
param = ECUtil.generatePublicKeyParameter(publicKey);
} else {
try {
byte[] bytes = publicKey.getEncoded();
publicKey = JDKKeyFactory.createPublicKeyFromDERStream(bytes);
if (publicKey instanceof ECPublicKey) {
param = ECUtil.generatePublicKeyParameter(publicKey);
} else {
throw new InvalidKeyException("can't recognise key type in ECDSA based signer");
}
} catch (Exception e) {
throw new InvalidKeyException("can't recognise key type in ECDSA based signer");
}
}
digest.reset();
signer.init(false, param);
}
use of org.bouncycastle.crypto.CipherParameters in project robovm by robovm.
the class DSASigner method engineInitSign.
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
CipherParameters param;
param = DSAUtil.generatePrivateKeyParameter(privateKey);
if (random != null) {
param = new ParametersWithRandom(param, random);
}
digest.reset();
signer.init(true, param);
}
Aggregations