use of com.github.zhenwei.core.crypto.signers.DSADigestSigner in project LinLong-Java by zhenwei1108.
the class BcITSContentSigner method getSignature.
public byte[] getSignature() {
byte[] clientCertDigest = new byte[digest.getDigestSize()];
digest.doFinal(clientCertDigest, 0);
final DSADigestSigner signer = new DSADigestSigner(new ECDSASigner(), digest);
signer.init(true, privKey);
signer.update(clientCertDigest, 0, clientCertDigest.length);
signer.update(parentDigest, 0, parentDigest.length);
return signer.generateSignature();
}
use of com.github.zhenwei.core.crypto.signers.DSADigestSigner in project LinLong-Java by zhenwei1108.
the class BcITSContentVerifierProvider method get.
public ContentVerifier get(final int verifierAlgorithmIdentifier) throws OperatorCreationException {
if (sigChoice != verifierAlgorithmIdentifier) {
throw new OperatorCreationException("wrong verifier for algorithm: " + verifierAlgorithmIdentifier);
}
final Digest digest = BcDefaultDigestProvider.INSTANCE.get(digestAlgo);
final byte[] parentDigest = new byte[digest.getDigestSize()];
digest.update(parentData, 0, parentData.length);
digest.doFinal(parentDigest, 0);
final byte[] parentTBSDigest = issuer.getIssuer().isSelf() ? new byte[digest.getDigestSize()] : null;
if (parentTBSDigest != null) {
byte[] enc = OEREncoder.toByteArray(issuer.toASN1Structure().getCertificateBase().getToBeSignedCertificate(), IEEE1609dot2.tbsCertificate);
digest.update(enc, 0, enc.length);
digest.doFinal(parentTBSDigest, 0);
}
final OutputStream os = new OutputStream() {
public void write(int b) throws IOException {
digest.update((byte) b);
}
public void write(byte[] b) throws IOException {
digest.update(b, 0, b.length);
}
public void write(byte[] b, int off, int len) throws IOException {
digest.update(b, off, len);
}
};
return new ContentVerifier() {
final DSADigestSigner signer = new DSADigestSigner(new ECDSASigner(), BcDefaultDigestProvider.INSTANCE.get(digestAlgo));
public AlgorithmIdentifier getAlgorithmIdentifier() {
return null;
}
public OutputStream getOutputStream() {
return os;
}
public boolean verify(byte[] expected) {
byte[] clientCertDigest = new byte[digest.getDigestSize()];
digest.doFinal(clientCertDigest, 0);
// System.out.println("Verify: "+ Hex.toHexString(clientCertDigest));
signer.init(false, pubParams);
signer.update(clientCertDigest, 0, clientCertDigest.length);
//
if (parentTBSDigest != null && Arrays.areEqual(clientCertDigest, parentTBSDigest)) {
byte[] empty = new byte[digest.getDigestSize()];
digest.doFinal(empty, 0);
// System.out.println("Empty: "+Hex.toHexString(empty));
signer.update(empty, 0, empty.length);
} else {
signer.update(parentDigest, 0, parentDigest.length);
}
return signer.verifySignature(expected);
}
};
}
use of com.github.zhenwei.core.crypto.signers.DSADigestSigner in project LinLong-Java by zhenwei1108.
the class BcECContentVerifierProviderBuilder method createSigner.
protected Signer createSigner(AlgorithmIdentifier sigAlgId) throws OperatorCreationException {
AlgorithmIdentifier digAlg = digestAlgorithmFinder.find(sigAlgId);
Digest dig = digestProvider.get(digAlg);
return new DSADigestSigner(new ECDSASigner(), dig);
}
use of com.github.zhenwei.core.crypto.signers.DSADigestSigner in project LinLong-Java by zhenwei1108.
the class BcDSAContentVerifierProviderBuilder method createSigner.
protected Signer createSigner(AlgorithmIdentifier sigAlgId) throws OperatorCreationException {
AlgorithmIdentifier digAlg = digestAlgorithmFinder.find(sigAlgId);
Digest dig = digestProvider.get(digAlg);
return new DSADigestSigner(new DSASigner(), dig);
}
Aggregations