use of com.github.zhenwei.pkix.operator.ContentVerifierProvider in project LinLong-Java by zhenwei1108.
the class JcaContentVerifierProviderBuilder method build.
public ContentVerifierProvider build(final PublicKey publicKey) throws OperatorCreationException {
return new ContentVerifierProvider() {
public boolean hasAssociatedCertificate() {
return false;
}
public X509CertificateHolder getAssociatedCertificate() {
return null;
}
public ContentVerifier get(AlgorithmIdentifier algorithm) throws OperatorCreationException {
if (algorithm.getAlgorithm().equals(MiscObjectIdentifiers.id_alg_composite)) {
return createCompositeVerifier(algorithm, publicKey);
}
if (publicKey instanceof CompositePublicKey) {
List<PublicKey> keys = ((CompositePublicKey) publicKey).getPublicKeys();
for (int i = 0; i != keys.size(); i++) {
try {
Signature sig = createSignature(algorithm, (PublicKey) keys.get(i));
Signature rawSig = createRawSig(algorithm, (PublicKey) keys.get(i));
if (rawSig != null) {
return new RawSigVerifier(algorithm, sig, rawSig);
} else {
return new SigVerifier(algorithm, sig);
}
} catch (OperatorCreationException e) {
// skip incorrect keys
}
}
throw new OperatorCreationException("no matching algorithm found for key");
} else {
Signature sig = createSignature(algorithm, publicKey);
Signature rawSig = createRawSig(algorithm, publicKey);
if (rawSig != null) {
return new RawSigVerifier(algorithm, sig, rawSig);
} else {
return new SigVerifier(algorithm, sig);
}
}
}
};
}
use of com.github.zhenwei.pkix.operator.ContentVerifierProvider in project LinLong-Java by zhenwei1108.
the class JcaContentVerifierProviderBuilder method build.
public ContentVerifierProvider build(final X509Certificate certificate) throws OperatorCreationException {
final X509CertificateHolder certHolder;
try {
certHolder = new JcaX509CertificateHolder(certificate);
} catch (CertificateEncodingException e) {
throw new OperatorCreationException("cannot process certificate: " + e.getMessage(), e);
}
return new ContentVerifierProvider() {
public boolean hasAssociatedCertificate() {
return true;
}
public X509CertificateHolder getAssociatedCertificate() {
return certHolder;
}
public ContentVerifier get(AlgorithmIdentifier algorithm) throws OperatorCreationException {
if (algorithm.getAlgorithm().equals(MiscObjectIdentifiers.id_alg_composite)) {
return createCompositeVerifier(algorithm, certificate.getPublicKey());
} else {
Signature sig;
try {
sig = helper.createSignature(algorithm);
sig.initVerify(certificate.getPublicKey());
} catch (GeneralSecurityException e) {
throw new OperatorCreationException("exception on setup: " + e, e);
}
Signature rawSig = createRawSig(algorithm, certificate.getPublicKey());
if (rawSig != null) {
return new RawSigVerifier(algorithm, sig, rawSig);
} else {
return new SigVerifier(algorithm, sig);
}
}
}
};
}
use of com.github.zhenwei.pkix.operator.ContentVerifierProvider in project LinLong-Java by zhenwei1108.
the class BcContentVerifierProviderBuilder method build.
public ContentVerifierProvider build(final X509CertificateHolder certHolder) throws OperatorCreationException {
return new ContentVerifierProvider() {
public boolean hasAssociatedCertificate() {
return true;
}
public X509CertificateHolder getAssociatedCertificate() {
return certHolder;
}
public ContentVerifier get(AlgorithmIdentifier algorithm) throws OperatorCreationException {
try {
AsymmetricKeyParameter publicKey = extractKeyParameters(certHolder.getSubjectPublicKeyInfo());
BcSignerOutputStream stream = createSignatureStream(algorithm, publicKey);
return new SigVerifier(algorithm, stream);
} catch (IOException e) {
throw new OperatorCreationException("exception on setup: " + e, e);
}
}
};
}
Aggregations