use of com.github.zhenwei.core.asn1.DEROctetString in project certmgr by hdecarne.
the class AuthorityKeyIdentifierExtensionData method encode.
@Override
public ASN1Encodable encode() throws IOException {
ASN1EncodableVector sequence = new ASN1EncodableVector();
byte[] checkedKeyIdentifier = this.keyIdentifier;
if (checkedKeyIdentifier != null) {
sequence.add(new DERTaggedObject(false, 0, new DEROctetString(checkedKeyIdentifier)));
}
GeneralNames checkedAuthorityCertIssuer = this.authorityCertIssuer;
if (checkedAuthorityCertIssuer != null) {
sequence.add(new DERTaggedObject(false, 1, checkedAuthorityCertIssuer.encode()));
}
BigInteger checkedAuthorityCertSerialNumber = this.authorityCertSerialNumber;
if (checkedAuthorityCertSerialNumber != null) {
sequence.add(new DERTaggedObject(false, 2, new ASN1Integer(checkedAuthorityCertSerialNumber)));
}
return new DERSequence(sequence);
}
use of com.github.zhenwei.core.asn1.DEROctetString in project hedera-services by hashgraph.
the class Ed25519PrivateKey method toString.
@Override
public String toString() {
PrivateKeyInfo privateKeyInfo;
try {
privateKeyInfo = new PrivateKeyInfo(new AlgorithmIdentifier(EdECObjectIdentifiers.id_Ed25519), new DEROctetString(privKeyParams.getEncoded()));
} catch (IOException e) {
throw new RuntimeException(e);
}
byte[] encoded;
try {
encoded = privateKeyInfo.getEncoded("DER");
} catch (IOException e) {
throw new RuntimeException(e);
}
return CommonUtils.hex(encoded);
}
use of com.github.zhenwei.core.asn1.DEROctetString in project gdmatrix by gdmatrix.
the class P7MUtils method printAttribute.
public static void printAttribute(Attribute attribute) throws Exception {
ASN1Set set = attribute.getAttrValues();
ASN1Primitive der = set.getObjectAt(0).toASN1Primitive();
System.out.println(der.getClass());
if (der instanceof DEROctetString) {
DEROctetString octet = (DEROctetString) der;
byte[] data = octet.getOctets();
System.out.println(new String(data, "UTF-16LE"));
} else if (der instanceof ASN1UTCTime) {
ASN1UTCTime utcTime = (ASN1UTCTime) der;
String time = utcTime.getAdjustedTime();
System.out.println(time);
} else if (der instanceof ASN1ObjectIdentifier) {
ASN1ObjectIdentifier id = (ASN1ObjectIdentifier) der;
System.out.println(id.getId());
}
}
use of com.github.zhenwei.core.asn1.DEROctetString in project signer by demoiselle.
the class BasicCertificate method getAuthorityKeyIdentifier.
/**
* *
*
* @return the authority key identifier of a certificate
*/
public String getAuthorityKeyIdentifier() {
// TODO - Precisa validar este metodo com a RFC
try {
DLSequence sequence = (DLSequence) getExtensionValue(Extension.authorityKeyIdentifier.getId());
if (sequence == null || sequence.size() == 0) {
return null;
}
DERTaggedObject taggedObject = (DERTaggedObject) sequence.getObjectAt(0);
DEROctetString oct = (DEROctetString) taggedObject.getObject();
return toString(oct.getOctets());
} catch (Exception error) {
logger.error(error.getMessage());
return null;
}
}
use of com.github.zhenwei.core.asn1.DEROctetString in project signer by demoiselle.
the class RevocationRefs method makeCrlValidatedID.
/**
* @param crl CrlValidatedID from X509CRL
* @return a CrlValidatedID
* @throws NoSuchAlgorithmException
* @throws CRLException
*/
private CrlValidatedID makeCrlValidatedID(X509CRL crl) throws CRLException {
Digest digest = DigestFactory.getInstance().factoryDefault();
digest.setAlgorithm(DigestAlgorithmEnum.SHA_256);
OtherHashAlgAndValue otherHashAlgAndValue = new OtherHashAlgAndValue(new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256), new DEROctetString(digest.digest(crl.getEncoded())));
OtherHash hash = new OtherHash(otherHashAlgAndValue);
BigInteger crlnumber;
CrlIdentifier crlid;
if (crl.getExtensionValue("2.5.29.20") != null) {
ASN1Integer varASN1Integer = new ASN1Integer(crl.getExtensionValue("2.5.29.20"));
crlnumber = varASN1Integer.getPositiveValue();
crlid = new CrlIdentifier(new X500Name(crl.getIssuerX500Principal().getName()), new DERUTCTime(crl.getThisUpdate()), crlnumber);
} else {
crlid = new CrlIdentifier(new X500Name(crl.getIssuerX500Principal().getName()), new DERUTCTime(crl.getThisUpdate()));
}
CrlValidatedID crlvid = new CrlValidatedID(hash, crlid);
return crlvid;
}
Aggregations