List of usage examples for org.bouncycastle.asn1 ASN1EncodableVector add
public void add(ASN1Encodable element)
From source file:com.goodvikings.cryptim.api.KeyRing.java
License:BEER-WARE LICENSE
private byte[] ASN1EncodeKeys() throws IOException, PGPException { JcaPGPKeyConverter converter = new JcaPGPKeyConverter(); PrivateKey priv = converter.getPrivateKey(kp.getPrivateKey()); PublicKey pub = converter.getPublicKey(kp.getPublicKey()); ASN1EncodableVector pubSeq = new ASN1EncodableVector(); for (String jid : keys.keySet()) { pubSeq.add(new DERSequence(new ASN1Encodable[] { new DERUTF8String(jid), new DERUTF8String(nicks.get(jid)), new DERUTCTime(keys.get(jid).getCreationTime()), new DEROctetString(converter.getPublicKey(keys.get(jid)).getEncoded()) })); }//from w w w . ja va 2s. co m DERSequence seq = new DERSequence(new ASN1Encodable[] { new DERSequence(new ASN1Encodable[] { new DERUTCTime(kp.getPublicKey().getCreationTime()), new DEROctetString(pub.getEncoded()) }), new DEROctetString(priv.getEncoded()), new DERSequence(pubSeq) }); return seq.getEncoded(); }
From source file:com.guardtime.asn1.Asn1Util.java
License:Apache License
/** * Extends the given content info with data from the given certification * token./*from w w w.j a va 2s . co m*/ * * @param contentInfo * the original timestamp encoded in a CMS {@code ContentInfo} * structure. * @param certToken * the {@code CertToken} from the GuardTime online verification * service. * @return updated (extended) timestamp encoded in a new CMS * {@code ContentInfo} structure. */ static org.bouncycastle.asn1.cms.ContentInfo extend(org.bouncycastle.asn1.cms.ContentInfo contentInfo, Asn1CertToken certToken) throws Asn1FormatException { ASN1EncodableVector v; // Extract signed data ASN1Encodable asn1SignedData = contentInfo.getContent(); org.bouncycastle.asn1.cms.SignedData content = org.bouncycastle.asn1.cms.SignedData .getInstance(asn1SignedData); // Extract signer info ASN1Encodable asn1SignerInfo = content.getSignerInfos().getObjectAt(0); org.bouncycastle.asn1.cms.SignerInfo signerInfo = org.bouncycastle.asn1.cms.SignerInfo .getInstance(asn1SignerInfo); // Extract time signature ASN1Primitive asn1TimeSignature = null; try { asn1TimeSignature = ASN1Primitive.fromByteArray(signerInfo.getEncryptedDigest().getOctets()); } catch (IOException e) { throw new Asn1FormatException("time signature has invalid format"); } Asn1TimeSignature timeSignature = Asn1TimeSignature.getInstance(asn1TimeSignature); // Extend TimeSignature v = new ASN1EncodableVector(); v.add(timeSignature.getLocation()); v.add(certToken.getHistory()); v.add(certToken.getPublishedData()); // Skip PK signature <- updated v.add(new DERTaggedObject(false, 1, certToken.getPubReference())); timeSignature = Asn1TimeSignature.getInstance(new DERSequence(v)); // Extend SignerInfo v = new ASN1EncodableVector(); v.add(signerInfo.getVersion()); v.add(signerInfo.getSID()); v.add(signerInfo.getDigestAlgorithm()); ASN1Set signedAttrs = signerInfo.getAuthenticatedAttributes(); if (signedAttrs != null) { v.add(new DERTaggedObject(false, 0, signedAttrs)); } v.add(signerInfo.getDigestEncryptionAlgorithm()); try { v.add(new DEROctetString(timeSignature)); // <- updated } catch (IOException e) { throw new Asn1FormatException(e); } ASN1Set unsignedAttrs = signerInfo.getUnauthenticatedAttributes(); if (unsignedAttrs != null) { v.add(new DERTaggedObject(false, 1, unsignedAttrs)); } signerInfo = org.bouncycastle.asn1.cms.SignerInfo.getInstance(new DERSequence(v)); // Extend SignedData v = new ASN1EncodableVector(); v.add(content.getVersion()); v.add(content.getDigestAlgorithms()); v.add(content.getEncapContentInfo()); // Skipping certificates <- updated // Skipping CRLs <- updated v.add(new DERSet(signerInfo)); // <- updated content = org.bouncycastle.asn1.cms.SignedData.getInstance(new DERSequence(v)); // Extend ContentInfo v = new ASN1EncodableVector(); v.add(contentInfo.getContentType()); v.add(new DERTaggedObject(true, 0, content)); // <- updated contentInfo = org.bouncycastle.asn1.cms.ContentInfo.getInstance(new DERSequence(v)); return contentInfo; }
From source file:com.guardtime.asn1.CertToken.java
License:Apache License
public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(version); v.add(history);//w w w.jav a 2 s . c o m v.add(publishedData); v.add(pubReference); if (extensions != null) { v.add(new DERTaggedObject(false, 0, extensions)); } return new DERSequence(v); }
From source file:com.guardtime.asn1.CertTokenRequest.java
License:Apache License
/** * Composes a new {@code CertTokenRequest} structure containing the given * history identifier and no extensions. * * @param historyId//from w ww .j av a 2 s. c o m * identifier of the second for which the certification token in * requested. * @return a new certification token request. */ public static CertTokenRequest compose(BigInteger historyId) { if (historyId == null) { throw new IllegalArgumentException("invalid history ID: null"); } ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new ASN1Integer(VERSION)); v.add(new ASN1Integer(historyId)); ASN1Sequence seq = new DERSequence(v); Asn1CertTokenRequest req = new Asn1CertTokenRequest(seq); return new CertTokenRequest(req); }
From source file:com.guardtime.asn1.CertTokenRequest.java
License:Apache License
public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(version); v.add(historyIdentifier);//ww w .jav a 2 s . co m if (extensions != null) { v.add(new DERTaggedObject(false, 0, extensions)); } return new DERSequence(v); }
From source file:com.guardtime.asn1.CertTokenResponse.java
License:Apache License
public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(status); if (certToken != null) { v.add(new DERTaggedObject(0, certToken)); }/* w w w. jav a2 s .c om*/ return new DERSequence(v); }
From source file:com.guardtime.asn1.PublishedData.java
License:Apache License
public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(publicationIdentifier); v.add(publicationImprint);// w ww .j a v a2s .com return new DERSequence(v); }
From source file:com.guardtime.asn1.SignatureInfo.java
License:Apache License
public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(signatureAlgorithm); v.add(signatureValue);// w ww .j a v a 2 s . co m if (pkiReferences != null) { v.add(new DERTaggedObject(false, 0, pkiReferences)); } return new DERSequence(v); }
From source file:com.guardtime.asn1.TimeSignature.java
License:Apache License
public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(location); v.add(history);/*w ww . ja v a2s .co m*/ v.add(publishedData); if (pkSignature != null) { v.add(new DERTaggedObject(false, 0, pkSignature)); } if (pubReferences != null) { v.add(new DERTaggedObject(false, 1, pubReferences)); } return new DERSequence(v); }
From source file:com.hierynomus.spnego.NegTokenInit.java
License:Apache License
private void addMechToken(ASN1EncodableVector negTokenInit) { if (mechToken != null && mechToken.length > 0) { ASN1Primitive token = new DERTaggedObject(true, 0x02, new DEROctetString(mechToken)); negTokenInit.add(token); }/* w ww. j av a 2 s .c o m*/ }