Methods Summary |
---|
private org.bouncycastle.asn1.x509.DigestInfo | derDecode(byte[] encoding)
ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
DERInputStream dIn = new DERInputStream(bIn);
return new DigestInfo((ASN1Sequence)dIn.readObject());
|
private byte[] | derEncode(byte[] hash)
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
DigestInfo dInfo = new DigestInfo(algId, hash);
dOut.writeObject(dInfo);
return bOut.toByteArray();
|
protected java.lang.Object | engineGetParameter(java.lang.String param)
throw new UnsupportedOperationException("engineSetParameter unsupported");
|
protected void | engineInitSign(java.security.PrivateKey privateKey)
if ( !(privateKey instanceof RSAPrivateKey) )
{
throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
}
CipherParameters param = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey);
digest.reset();
cipher.init(true, param);
|
protected void | engineInitVerify(java.security.PublicKey publicKey)
if ( !(publicKey instanceof RSAPublicKey) )
{
throw new InvalidKeyException("Supplied key is not a RSAPublicKey instance");
}
CipherParameters param = RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey);
digest.reset();
cipher.init(false, param);
|
protected void | engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
throw new UnsupportedOperationException("engineSetParameter unsupported");
|
protected void | engineSetParameter(java.lang.String param, java.lang.Object value)
throw new UnsupportedOperationException("engineSetParameter unsupported");
|
protected byte[] | engineSign()
byte[] hash = new byte[digest.getDigestSize()];
digest.doFinal(hash, 0);
try
{
byte[] bytes = derEncode(hash);
return cipher.processBlock(bytes, 0, bytes.length);
}
catch (ArrayIndexOutOfBoundsException e)
{
throw new SignatureException("key too small for signature type");
}
catch (Exception e)
{
throw new SignatureException(e.toString());
}
|
protected void | engineUpdate(byte b)
digest.update(b);
|
protected void | engineUpdate(byte[] b, int off, int len)
digest.update(b, off, len);
|
protected boolean | engineVerify(byte[] sigBytes)
byte[] hash = new byte[digest.getDigestSize()];
digest.doFinal(hash, 0);
DigestInfo digInfo;
byte[] sig;
try
{
sig = cipher.processBlock(sigBytes, 0, sigBytes.length);
digInfo = derDecode(sig);
}
catch (Exception e)
{
return false;
}
if (!digInfo.getAlgorithmId().equals(algId))
{
return false;
}
byte[] sigHash = digInfo.getDigest();
if (hash.length != sigHash.length)
{
return false;
}
for (int i = 0; i < hash.length; i++)
{
if (sigHash[i] != hash[i])
{
return false;
}
}
return true;
|