Methods Summary |
---|
private byte[] | derEncode(byte[] hash)
DigestInfo dInfo = new DigestInfo(algId, hash);
return dInfo.getEncoded(ASN1Encodable.DER);
|
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 (" + getType(privateKey) + ") 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 (" + getType(publicKey) + ") is not a RSAPublicKey instance");
}
CipherParameters param = RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey);
digest.reset();
cipher.init(false, param);
|
protected void | engineSetParameter(java.lang.String param, java.lang.Object value)
throw new UnsupportedOperationException("engineSetParameter unsupported");
|
protected void | engineSetParameter(java.security.spec.AlgorithmParameterSpec params)
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);
byte[] sig;
byte[] expected;
try
{
sig = cipher.processBlock(sigBytes, 0, sigBytes.length);
expected = derEncode(hash);
}
catch (Exception e)
{
return false;
}
if (sig.length == expected.length)
{
for (int i = 0; i < sig.length; i++)
{
if (sig[i] != expected[i])
{
return false;
}
}
}
else if (expected.length == sig.length - 2) // NULL left out
{
int sigOffset = sig.length - hash.length - 2;
int expectedOffset = expected.length - hash.length - 2;
sig[1] -= 2; // adjust lengths
sig[3] -= 2;
for (int i = 0; i < hash.length; i++)
{
if (sig[sigOffset + i] != expected[expectedOffset + i]) // check hash
{
return false;
}
}
for (int i = 0; i < expectedOffset; i++)
{
if (sig[i] != expected[i]) // check header less NULL
{
return false;
}
}
}
else
{
return false;
}
return true;
|
private java.lang.String | getType(java.lang.Object o)
if (o == null)
{
return null;
}
return o.getClass().getName();
|