📄 jdkdsasigner.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: JDKDSASigner.java
package org.bouncycastle.jce.provider;
import java.io.*;
import java.math.BigInteger;
import java.security.*;
import java.security.interfaces.DSAKey;
import java.security.spec.AlgorithmParameterSpec;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.X509ObjectIdentifiers;
import org.bouncycastle.crypto.DSA;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.SHA1Digest;
import org.bouncycastle.crypto.params.ParametersWithRandom;
import org.bouncycastle.crypto.signers.ECDSASigner;
import org.bouncycastle.jce.interfaces.ECKey;
// Referenced classes of package org.bouncycastle.jce.provider:
// DSAUtil, ECUtil
public class JDKDSASigner extends Signature
implements PKCSObjectIdentifiers, X509ObjectIdentifiers
{
public static class ecDSA extends JDKDSASigner
{
public ecDSA()
{
super("SHA1withECDSA", new SHA1Digest(), new ECDSASigner());
}
}
private Digest digest;
private DSA signer;
private SecureRandom random;
protected JDKDSASigner(String name, Digest digest, DSA signer)
{
super(name);
this.digest = digest;
this.signer = signer;
}
protected void engineInitVerify(PublicKey publicKey)
throws InvalidKeyException
{
org.bouncycastle.crypto.CipherParameters param = null;
if (publicKey instanceof ECKey)
param = ECUtil.generatePublicKeyParameter(publicKey);
else
if (publicKey instanceof DSAKey)
param = DSAUtil.generatePublicKeyParameter(publicKey);
else
try
{
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
catch (Exception e)
{
throw new InvalidKeyException("can't recognise key type in DSA based signer");
}
digest.reset();
signer.init(false, param);
}
protected void engineInitSign(PrivateKey privateKey, SecureRandom random)
throws InvalidKeyException
{
this.random = random;
engineInitSign(privateKey);
}
protected void engineInitSign(PrivateKey privateKey)
throws InvalidKeyException
{
org.bouncycastle.crypto.CipherParameters param = null;
if (privateKey instanceof ECKey)
param = ECUtil.generatePrivateKeyParameter(privateKey);
else
param = DSAUtil.generatePrivateKeyParameter(privateKey);
digest.reset();
if (random != null)
signer.init(true, new ParametersWithRandom(param, random));
else
signer.init(true, param);
}
protected void engineUpdate(byte b)
throws SignatureException
{
digest.update(b);
}
protected void engineUpdate(byte b[], int off, int len)
throws SignatureException
{
digest.update(b, off, len);
}
protected byte[] engineSign()
throws SignatureException
{
byte hash[];
hash = new byte[digest.getDigestSize()];
digest.doFinal(hash, 0);
BigInteger sig[] = signer.generateSignature(hash);
return derEncode(sig[0], sig[1]);
Exception e;
e;
throw new SignatureException(e.toString());
}
protected boolean engineVerify(byte sigBytes[])
throws SignatureException
{
byte hash[] = new byte[digest.getDigestSize()];
digest.doFinal(hash, 0);
BigInteger sig[];
try
{
sig = derDecode(sigBytes);
}
catch (Exception e)
{
throw new SignatureException("error decoding signature bytes.");
}
return signer.verifySignature(hash, sig[0], sig[1]);
}
protected void engineSetParameter(AlgorithmParameterSpec params)
{
throw new UnsupportedOperationException("engineSetParameter unsupported");
}
/**
* @deprecated Method engineSetParameter is deprecated
*/
protected void engineSetParameter(String param, Object value)
{
throw new UnsupportedOperationException("engineSetParameter unsupported");
}
/**
* @deprecated Method engineGetParameter is deprecated
*/
protected Object engineGetParameter(String param)
{
throw new UnsupportedOperationException("engineSetParameter unsupported");
}
private byte[] derEncode(BigInteger r, BigInteger s)
throws IOException
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(new DERInteger(r));
v.add(new DERInteger(s));
dOut.writeObject(new DERSequence(v));
return bOut.toByteArray();
}
private BigInteger[] derDecode(byte encoding[])
throws IOException
{
ByteArrayInputStream bIn = new ByteArrayInputStream(encoding);
DERInputStream dIn = new DERInputStream(bIn);
ASN1Sequence s = (ASN1Sequence)dIn.readObject();
BigInteger sig[] = new BigInteger[2];
sig[0] = ((DERInteger)s.getObjectAt(0)).getValue();
sig[1] = ((DERInteger)s.getObjectAt(1)).getValue();
return sig;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -