List of usage examples for org.bouncycastle.asn1 DEROctetString DEROctetString
public DEROctetString(ASN1Encodable obj) throws IOException
From source file:tests.asn1.TimeSignatureTest.java
License:Apache License
/** * Produces input stream containing ASN.1 representation of time signature. */// w w w. j a va2 s. c o m private InputStream getDerStream(byte[] location, byte[] history, byte[] publishedData, DERTaggedObject pkSignature, DERTaggedObject pubReferences) throws IOException { ASN1EncodableVector v = new ASN1EncodableVector(); if (location != null) { v.add(new DEROctetString(location)); } if (history != null) { v.add(new DEROctetString(history)); } if (publishedData != null) { v.add(new ASN1InputStream(publishedData).readObject()); } if (pkSignature != null) { v.add(pkSignature); } if (pubReferences != null) { v.add(pubReferences); } byte[] der = new DERSequence(v).getEncoded(ASN1Encoding.DER); return new ByteArrayInputStream(der); }
From source file:tests.asn1.TimeSignatureTest.java
License:Apache License
/** * Produces ASN.1 tagged object./* w ww.jav a 2s .co m*/ */ private DERTaggedObject getDerTagged(boolean isExplicit, int tagNumber, byte[][] pubReferences) throws IOException { DEROctetString[] derRefs = new DEROctetString[pubReferences.length]; for (int i = 0; i < pubReferences.length; i++) { derRefs[i] = new DEROctetString(pubReferences[i]); } return new DERTaggedObject(isExplicit, tagNumber, new DERSet(derRefs)); }
From source file:tr.gov.turkiye.esign.cms.MessageDigest.java
/** * Creates MessageDigest instance//ww w . j ava 2 s. co m * @param content the input for digest * @param isSHA256 the algorithm requested is SHA256 or not * @throws SmartCardException */ public MessageDigest(byte[] content, boolean isSHA256) throws SmartCardException { byte[] contentDigestBytes; if (isSHA256) { contentDigestBytes = Util.digestSHA256(content); } else { contentDigestBytes = Util.digestSHA1(content); } contentDigest = new DEROctetString(contentDigestBytes); }
From source file:tr.gov.turkiye.esign.cms.SignedData.java
/** * It is the signed content, consisting of a content type identifier and the content itself * @param content the bytes of content to be signed. * @return DERSequence instance/*from w w w. j a va 2 s . c o m*/ */ private ASN1Encodable getContentInfo(byte[] content) { final ASN1EncodableVector v = new ASN1EncodableVector(); v.add(ObjectID.pkcs7_data); DEROctetString ds = new DEROctetString(content); DERTaggedObject to = new DERTaggedObject(true, 0, ds); v.add(to); DERSequence ddd = new DERSequence(v); return ddd; }
From source file:tr.gov.turkiye.esign.cms.SignerInfo.java
/** * the result of digital signature generation, using the message digest and the signer's private key * @return DEROctetString instance//from ww w . jav a 2 s . c o m */ private ASN1Encodable getSignedDigest() { return new DEROctetString(encryptedDigest); }
From source file:tr.gov.turkiye.esign.cms.SignerInfo.java
/** * Gets encoded bytes of authenticated attributes * @return byte array//from w w w. ja va 2s .com * @throws SmartCardException */ public byte[] getEncodedAuthenticatedAttributes() throws SmartCardException { try { final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); final DEROutputStream dOut = new DEROutputStream(bOut); dOut.writeObject(getSignedAttributesSet()); final byte[] bytesToSign = bOut.toByteArray(); final byte[] bytesToSignHash = getHash(bytesToSign); ASN1EncodableVector v = new ASN1EncodableVector(); if (isSHA256) { v.add(ObjectID.idSHA256); } else { v.add(ObjectID.idSHA1); } v.add(DERNull.INSTANCE); final DERSequence algorithmIdentifier = new DERSequence(v); v = new ASN1EncodableVector(); v.add(algorithmIdentifier); v.add(new DEROctetString(bytesToSignHash)); final DERSequence digestInfo = new DERSequence(v); final byte[] bytes = digestInfo.getEncoded(); return bytes; } catch (IOException ex) { throw new SmartCardException(ExceptionSupport.getValue("IOException"), ex); } }
From source file:tr.gov.turkiye.esign.cms.SigningCertificate.java
/** * the certHash is computed over the entire DER encoded certificate including the signature * @param cert signing certificate//from www .j a va 2s.c o m * @return DEROctetString instance * @throws SmartCardException */ private ASN1Encodable getCertificateHash(Certificate cert) throws SmartCardException { try { byte[] certHash; if (isSHA256) { certHash = Util.digestSHA256(cert.getEncoded()); } else { certHash = Util.digestSHA1(cert.getEncoded()); } DEROctetString hash = new DEROctetString(certHash); return hash; } catch (CertificateEncodingException ex) { throw new SmartCardException(ExceptionSupport.getValue("CertificateEncodingException"), ex); } }
From source file:uk.ac.ox.webauth.asn1.EncryptedData.java
License:Open Source License
private EncryptedData(int etype, SecretKey key, int usage, ASN1Encodable o) throws IOException, GeneralSecurityException { this.etype = new DERInteger(etype); decrypted = o;/*w w w .j a va2 s .c o m*/ EType crypto = cryptoInstance(etype, key, usage); cipher = new DEROctetString(crypto.encrypt(o)); }