use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.
the class CertificationRequest method toASN1Primitive.
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector(3);
v.add(certificationRequestInfo);
v.add(signatureAlgorithm);
v.add(signature);
return new DERSequence(v);
}
use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.
the class CVCertificate method toASN1Primitive.
/**
* @see com.github.zhenwei.core.asn1.ASN1Object#toASN1Primitive()
*/
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector(2);
v.add(certificateBody);
try {
v.add(new DERApplicationSpecific(false, EACTags.STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP, new DEROctetString(signature)));
} catch (IOException e) {
throw new IllegalStateException("unable to convert signature!");
}
return new DERApplicationSpecific(EACTags.CARDHOLDER_CERTIFICATE, v);
}
use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.
the class CVCertificate method setPrivateData.
/**
* Sets the values of the certificate (body and signature).
*
* @param appSpe is a ASN1ApplicationSpecific object containing body and signature.
* @throws IOException if tags or value are incorrect.
*/
private void setPrivateData(ASN1ApplicationSpecific appSpe) throws IOException {
valid = 0;
if (appSpe.getApplicationTag() == EACTags.CARDHOLDER_CERTIFICATE) {
ASN1InputStream content = new ASN1InputStream(appSpe.getContents());
ASN1Primitive tmpObj;
while ((tmpObj = content.readObject()) != null) {
ASN1ApplicationSpecific aSpe;
if (tmpObj instanceof ASN1ApplicationSpecific) {
aSpe = (ASN1ApplicationSpecific) tmpObj;
switch(aSpe.getApplicationTag()) {
case EACTags.CERTIFICATE_CONTENT_TEMPLATE:
certificateBody = CertificateBody.getInstance(aSpe);
valid |= bodyValid;
break;
case EACTags.STATIC_INTERNAL_AUTHENTIFICATION_ONE_STEP:
signature = aSpe.getContents();
valid |= signValid;
break;
default:
throw new IOException("Invalid tag, not an Iso7816CertificateStructure :" + aSpe.getApplicationTag());
}
} else {
throw new IOException("Invalid Object, not an Iso7816CertificateStructure");
}
}
content.close();
} else {
throw new IOException("not a CARDHOLDER_CERTIFICATE :" + appSpe.getApplicationTag());
}
if (valid != (signValid | bodyValid)) {
throw new IOException("invalid CARDHOLDER_CERTIFICATE :" + appSpe.getApplicationTag());
}
}
use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.
the class SignatureSpiLe method engineVerify.
protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
byte[] bytes = null;
try {
bytes = ((ASN1OctetString) ASN1OctetString.fromByteArray(sigBytes)).getOctets();
} catch (IOException e) {
throw new SignatureException("error decoding signature bytes.");
}
reverseBytes(bytes);
try {
return super.engineVerify((new DEROctetString(bytes)).getEncoded());
} catch (SignatureException e) {
throw e;
} catch (Exception e) {
throw new SignatureException(e.toString());
}
}
use of com.github.zhenwei.core.asn1.ocsp.Signature in project LinLong-Java by zhenwei1108.
the class PKCS10CertificationRequest method verify.
/**
* verify the request using the passed in public key and the provider..
*/
public boolean verify(PublicKey pubKey, String provider) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException {
Signature sig;
try {
if (provider == null) {
sig = Signature.getInstance(getSignatureName(sigAlgId));
} else {
sig = Signature.getInstance(getSignatureName(sigAlgId), provider);
}
} catch (NoSuchAlgorithmException e) {
//
if (oids.get(sigAlgId.getAlgorithm()) != null) {
String signatureAlgorithm = (String) oids.get(sigAlgId.getAlgorithm());
if (provider == null) {
sig = Signature.getInstance(signatureAlgorithm);
} else {
sig = Signature.getInstance(signatureAlgorithm, provider);
}
} else {
throw e;
}
}
setSignatureParameters(sig, sigAlgId.getParameters());
sig.initVerify(pubKey);
try {
sig.update(reqInfo.getEncoded(ASN1Encoding.DER));
} catch (Exception e) {
throw new SignatureException("exception encoding TBS cert request - " + e);
}
return sig.verify(sigBits.getOctets());
}
Aggregations