public DHParameter( BigInteger p, BigInteger g, int l) { this.p = new DERInteger(p); this.g = new DERInteger(g); if (l != 0) { this.l = new DERInteger(l); } else { this.l = null; } }
public DHParameter( ASN1Sequence seq) { Enumeration e = seq.getObjects(); p = (DERInteger)e.nextElement(); g = (DERInteger)e.nextElement(); if (e.hasMoreElements()) { l = (DERInteger)e.nextElement(); } else { l = null; } }
public RSAPrivateKeyStructure( ASN1Sequence seq) { Enumeration e = seq.getObjects(); BigInteger v = ((DERInteger)e.nextElement()).getValue(); if (v.intValue() != 0 && v.intValue() != 1) { throw new IllegalArgumentException("wrong version for RSA private key"); } version = v.intValue(); modulus = ((DERInteger)e.nextElement()).getValue(); publicExponent = ((DERInteger)e.nextElement()).getValue(); privateExponent = ((DERInteger)e.nextElement()).getValue(); prime1 = ((DERInteger)e.nextElement()).getValue(); prime2 = ((DERInteger)e.nextElement()).getValue(); exponent1 = ((DERInteger)e.nextElement()).getValue(); exponent2 = ((DERInteger)e.nextElement()).getValue(); coefficient = ((DERInteger)e.nextElement()).getValue(); if (e.hasMoreElements()) { otherPrimeInfos = (ASN1Sequence)e.nextElement(); } }
public PBKDF2Params( ASN1Sequence seq) { Enumeration e = seq.getObjects(); octStr = (ASN1OctetString)e.nextElement(); iterationCount = (DERInteger)e.nextElement(); if (e.hasMoreElements()) { keyLength = (DERInteger)e.nextElement(); } else { keyLength = null; } }
private boolean isPKCSParam(ASN1Sequence seq) { if (seq.size() == 2) { return true; } if (seq.size() > 3) { return false; } DERInteger l = DERInteger.getInstance(seq.getObjectAt(2)); DERInteger p = DERInteger.getInstance(seq.getObjectAt(0)); if (l.getValue().compareTo(BigInteger.valueOf(p.getValue().bitLength())) > 0) { return false; } return true; }
public byte[] getEncoded() { try { if (dsaSpec == null) { return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa), new DERInteger(y)).getEncoded(ASN1Encoding.DER); } return new SubjectPublicKeyInfo(new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, new DSAParameter(dsaSpec.getP(), dsaSpec.getQ(), dsaSpec.getG())), new DERInteger(y)).getEncoded(ASN1Encoding.DER); } catch (IOException e) { return null; } }
private static byte[] derEncode(byte[] rawSign) throws IOException { int len = rawSign.length / 2; byte[] r = new byte[len]; byte[] s = new byte[len]; System.arraycopy(rawSign, 0, r, 0, len); System.arraycopy(rawSign, len, s, 0, len); ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new DERInteger(new BigInteger(1, r))); v.add(new DERInteger(new BigInteger(1, s))); DERSequence seq = new DERSequence(v); return seq.getEncoded(); }
/** * in the absence of a standard way of doing it this will do for * now... */ protected byte[] engineGetEncoded() { try { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new DEROctetString(currentSpec.getDerivationV())); v.add(new DEROctetString(currentSpec.getEncodingV())); v.add(new DERInteger(currentSpec.getMacKeySize())); return new DERSequence(v).getEncoded(ASN1Encoding.DER); } catch (IOException e) { throw new RuntimeException("Error encoding IESParameters"); } }
private PKIStatusInfo getPKIStatusInfo() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new DERInteger(status)); if (statusStrings.size() > 0) { v.add(PKIFreeText.getInstance(new DERSequence(statusStrings))); } if (failInfo != 0) { DERBitString failInfoBitString = new FailInfo(failInfo); v.add(failInfoBitString); } return PKIStatusInfo.getInstance(new DERSequence(v)); }
public AttributeCertificateHolder(X509Certificate cert) throws CertificateParsingException { X509Principal name; try { name = PrincipalUtil.getIssuerX509Principal(cert); } catch (Exception e) { throw new CertificateParsingException(e.getMessage()); } holder = new Holder(new IssuerSerial(generateGeneralNames(name), new DERInteger(cert.getSerialNumber()))); }
private BigInteger getCrlNumber(X509CRL crl) { byte[] crlNumberExtensionValue = crl.getExtensionValue(X509Extensions.CRLNumber.getId()); if (null == crlNumberExtensionValue) { return null; } try { ASN1InputStream asn1InputStream = new ASN1InputStream(crlNumberExtensionValue); ASN1OctetString octetString = (ASN1OctetString) asn1InputStream.readObject(); byte[] octets = octetString.getOctets(); DERInteger integer = (DERInteger) new ASN1InputStream(octets).readObject(); BigInteger crlNumber = integer.getPositiveValue(); return crlNumber; } catch (IOException e) { throw new RuntimeException("I/O error: " + e.getMessage(), e); } }
public byte[] buildCmsBody(String signedHashId, X509Certificate certContent, byte[] content, String hashId, int version) throws CertificateEncodingException, IOException { final DEREncodableVector whole = new DEREncodableVector(); whole.add(new DERObjectIdentifier(CMS_SIGNED_ID)); final DEREncodableVector body = new DEREncodableVector(); // ----- versao ------- // final int version = 1; body.add(new DERInteger(version)); buildDigestAlg(body, hashId); // buildContentInfo(body, content); buildCerts(body, certContent); buildSignerInfo(body, signedHashId, certContent, hashId); whole.add(new DERTaggedObject(0, new DERSequence(body))); return genOutput(new DERSequence(whole)); }
public byte[] buildCmsBody(byte[] signedHashId, X509Certificate certContent, List<X509Certificate> chain, int hashId, int version, int attachSize) throws Exception { final DEREncodableVector whole = new DEREncodableVector(); // 0 SEQ whole.add(new DERObjectIdentifier(CMS_SIGNED_ID)); // 1 SEQ final DEREncodableVector body = new DEREncodableVector(); // ----- versao ------- // final int version = 1; body.add(new DERInteger(version)); // 3 INT buildDigestAlg(body, getHashAlg(hashId)); // 3 SET buildContentInfo(body, attachSize); // 3 SEQ buildCerts(body, chain); // 3 CS buildSignerInfo(body, signedHashId, certContent, hashId); // 3 SET whole.add(new DERTaggedObject(0, new DERSequence( // 2 SEQ body))); // 1 CS return genOutput(new DERSequence(whole)); }
private void buildSignerInfo(DEREncodableVector body, byte[] signedHashContent, X509Certificate certContent, int hashId) throws Exception { // ----- Signers Info -------- final DEREncodableVector vec = new DEREncodableVector(); final DEREncodableVector signerinfoVector = new DEREncodableVector(); signerinfoVector.add(new DERInteger(SI_VERSION)); signerinfoVector.add(siAddCert(certContent)); signerinfoVector.add(siAddDigestAlgorithm(getHashAlg(hashId))); signerinfoVector .add(siAddDigestEncryptionAlgorithm(getHashSignAlg(hashId))); // Add the digest signerinfoVector.add(new DEROctetString(signedHashContent)); final DERSequence siSeq = new DERSequence(signerinfoVector); vec.add(siSeq); DERSet siSet = new DERSet(vec); body.add(siSet); }
private void buildSignerInfo(DEREncodableVector body, String signedHashContent, X509Certificate certContent, String hashId) throws CertificateEncodingException { // ----- Signers Info -------- final DEREncodableVector vec = new DEREncodableVector(); final DEREncodableVector signerinfoVector = new DEREncodableVector(); signerinfoVector.add(new DERInteger(SI_VERSION)); // 5 INT signerinfoVector.add(siAddCert(certContent)); signerinfoVector.add(siAddDigestAlgorithm(hashId)); signerinfoVector.add(siAddDigestEncryptionAlgorithm(ID_SHA1_RSA)); // 6 // OCT // STR // Add the digest signerinfoVector.add(new DEROctetString( getDerSignedDigest(signedHashContent))); final DERSequence siSeq = new DERSequence(signerinfoVector); // 4 SEQ vec.add(siSeq); DERSet siSet = new DERSet(vec); // 3 SET body.add(siSet); }
public byte[] buildCmsBody(String signedHashId, X509Certificate certContent, byte[] content, String hashId, int version) throws CertificateEncodingException, IOException { final ASN1EncodableVector whole = new ASN1EncodableVector(); whole.add(new DERObjectIdentifier(CMS_SIGNED_ID)); final ASN1EncodableVector body = new ASN1EncodableVector(); // ----- versao ------- // final int version = 1; body.add(new DERInteger(version)); buildDigestAlg(body, hashId); // buildContentInfo(body, content); buildCerts(body, certContent); buildSignerInfo(body, signedHashId, certContent, hashId); whole.add(new DERTaggedObject(0, new DERSequence(body))); return genOutput(new DERSequence(whole)); }
public byte[] buildCmsBody(byte[] signedHashId, X509Certificate certContent, List<X509Certificate> chain, int hashId, int version, int attachSize) throws Exception { final ASN1EncodableVector whole = new ASN1EncodableVector(); // 0 SEQ whole.add(new DERObjectIdentifier(CMS_SIGNED_ID)); // 1 SEQ final ASN1EncodableVector body = new ASN1EncodableVector(); // ----- versao ------- // final int version = 1; body.add(new DERInteger(version)); // 3 INT buildDigestAlg(body, getHashAlg(hashId)); // 3 SET buildContentInfo(body, attachSize); // 3 SEQ buildCerts(body, chain); // 3 CS buildSignerInfo(body, signedHashId, certContent, hashId); // 3 SET whole.add(new DERTaggedObject(0, new DERSequence( // 2 SEQ body))); // 1 CS return genOutput(new DERSequence(whole)); }
private void buildSignerInfo(ASN1EncodableVector body, byte[] signedHashContent, X509Certificate certContent, int hashId) throws Exception { // ----- Signers Info -------- final ASN1EncodableVector vec = new ASN1EncodableVector(); final ASN1EncodableVector signerinfoVector = new ASN1EncodableVector(); signerinfoVector.add(new DERInteger(SI_VERSION)); signerinfoVector.add(siAddCert(certContent)); signerinfoVector.add(siAddDigestAlgorithm(getHashAlg(hashId))); signerinfoVector .add(siAddDigestEncryptionAlgorithm(getHashSignAlg(hashId))); // Add the digest signerinfoVector.add(new DEROctetString(signedHashContent)); final DERSequence siSeq = new DERSequence(signerinfoVector); vec.add(siSeq); DERSet siSet = new DERSet(vec); body.add(siSet); }
private void buildSignerInfo(ASN1EncodableVector body, String signedHashContent, X509Certificate certContent, String hashId) throws CertificateEncodingException { // ----- Signers Info -------- final ASN1EncodableVector vec = new ASN1EncodableVector(); final ASN1EncodableVector signerinfoVector = new ASN1EncodableVector(); signerinfoVector.add(new DERInteger(SI_VERSION)); // 5 INT signerinfoVector.add(siAddCert(certContent)); signerinfoVector.add(siAddDigestAlgorithm(hashId)); signerinfoVector.add(siAddDigestEncryptionAlgorithm(ID_SHA1_RSA)); // 6 // OCT // STR // Add the digest signerinfoVector.add(new DEROctetString( getDerSignedDigest(signedHashContent))); final DERSequence siSeq = new DERSequence(signerinfoVector); // 4 SEQ vec.add(siSeq); DERSet siSet = new DERSet(vec); // 3 SET body.add(siSet); }
protected BigInteger[] derDecode( byte[] encoding) throws IOException { ByteArrayInputStream bIn = new ByteArrayInputStream(encoding); ASN1InputStream aIn = new ASN1InputStream(bIn); ASN1Sequence s = (ASN1Sequence)aIn.readObject(); aIn.close(); BigInteger[] sig = new BigInteger[2]; sig[0] = ((DERInteger)s.getObjectAt(0)).getValue(); sig[1] = ((DERInteger)s.getObjectAt(1)).getValue(); return sig; }
private byte[] derEncode( BigInteger r, BigInteger s) throws IOException { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new DERInteger(r)); v.add(new DERInteger(s)); dOut.writeObject(new DERSequence(v)); return bOut.toByteArray(); }
public ECPrivateKeyStructure( BigInteger key) { byte[] bytes = key.toByteArray(); if (bytes[0] == 0) { byte[] tmp = new byte[bytes.length - 1]; System.arraycopy(bytes, 1, tmp, 0, tmp.length); bytes = tmp; } ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new DERInteger(1)); v.add(new DEROctetString(bytes)); seq = new DERSequence(v); }
/** * Creates a new <code>NoticeReference</code> instance. * * @param orgName a <code>String</code> value * @param numbers a <code>Vector</code> value */ public NoticeReference( String orgName, Vector numbers) { organization = new DisplayText(orgName); Object o = numbers.elementAt(0); ASN1EncodableVector av = new ASN1EncodableVector(); if (o instanceof Integer) { Enumeration it = numbers.elements(); while (it.hasMoreElements()) { Integer nm = (Integer) it.nextElement(); DERInteger di = new DERInteger(nm.intValue()); av.add (di); } } noticeNumbers = new DERSequence(av); }
public AuthorityKeyIdentifier( ASN1Sequence seq) { Enumeration e = seq.getObjects(); while (e.hasMoreElements()) { ASN1TaggedObject o = DERTaggedObject.getInstance(e.nextElement()); switch (o.getTagNo()) { case 0: this.keyidentifier = ASN1OctetString.getInstance(o, false); break; case 1: this.certissuer = GeneralNames.getInstance(o, false); break; case 2: this.certserno = DERInteger.getInstance(o, false); break; default: throw new IllegalArgumentException("illegal tag"); } } }
/** * create an AuthorityKeyIdentifier with the GeneralNames tag and * the serial number provided as well. */ public AuthorityKeyIdentifier( SubjectPublicKeyInfo spki, GeneralNames name, BigInteger serialNumber) { Digest digest = new SHA1Digest(); byte[] resBuf = new byte[digest.getDigestSize()]; byte[] bytes = spki.getPublicKeyData().getBytes(); digest.update(bytes, 0, bytes.length); digest.doFinal(resBuf, 0); this.keyidentifier = new DEROctetString(resBuf); this.certissuer = GeneralNames.getInstance(name.toASN1Object()); this.certserno = new DERInteger(serialNumber); }
public CRLEntry( ASN1Sequence seq) { if (seq.size() < 2 || seq.size() > 3) { throw new IllegalArgumentException("Bad sequence size: " + seq.size()); } this.seq = seq; userCertificate = DERInteger.getInstance(seq.getObjectAt(0)); revocationDate = Time.getInstance(seq.getObjectAt(1)); if (seq.size() == 3) { crlEntryExtensions = X509Extensions.getInstance(seq.getObjectAt(2)); } }
/** * Constructor from a given details. * * According RFC 3280, the minimum and maximum fields are not used with any * name forms, thus minimum MUST be zero, and maximum MUST be absent. * <p> * If minimum is <code>null</code>, zero is assumed, if * maximum is <code>null</code>, maximum is absent. * * @param base * A restriction. * @param minimum * Minimum * * @param maximum * Maximum */ public GeneralSubtree( GeneralName base, BigInteger minimum, BigInteger maximum) { this.base = base; if (maximum != null) { this.maximum = new DERInteger(maximum); } if (minimum == null) { this.minimum = null; } else { this.minimum = new DERInteger(minimum); } }
/** * @deprecated use one of the other two unambigous constructors. * @param cA * @param pathLenConstraint */ public BasicConstraints( boolean cA, int pathLenConstraint) { if (cA) { this.cA = new DERBoolean(cA); this.pathLenConstraint = new DERInteger(pathLenConstraint); } else { this.cA = null; this.pathLenConstraint = null; } }
public IssuerSerial( ASN1Sequence seq) { if (seq.size() != 2 && seq.size() != 3) { throw new IllegalArgumentException("Bad sequence size: " + seq.size()); } issuer = GeneralNames.getInstance(seq.getObjectAt(0)); serial = DERInteger.getInstance(seq.getObjectAt(1)); if (seq.size() == 3) { issuerUID = DERBitString.getInstance(seq.getObjectAt(2)); } }
public X9Curve( X9FieldID fieldID, ASN1Sequence seq) { if (fieldID.getIdentifier().equals(prime_field)) { BigInteger q = ((DERInteger)fieldID.getParameters()).getValue(); X9FieldElement x9A = new X9FieldElement(true, q, (ASN1OctetString)seq.getObjectAt(0)); X9FieldElement x9B = new X9FieldElement(true, q, (ASN1OctetString)seq.getObjectAt(1)); curve = new ECCurve.Fp(q, x9A.getValue().toBigInteger(), x9B.getValue().toBigInteger()); } else { throw new RuntimeException("not implemented"); } if (seq.size() == 3) { seed = ((DERBitString)seq.getObjectAt(2)).getBytes(); } }
/** * Produce an object suitable for an ASN1OutputStream. * <pre> * ECParameters ::= SEQUENCE { * version INTEGER { ecpVer1(1) } (ecpVer1), * fieldID FieldID {{FieldTypes}}, * curve X9Curve, * base X9ECPoint, * order INTEGER, * cofactor INTEGER OPTIONAL * } * </pre> */ public DERObject getDERObject() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(new DERInteger(1)); v.add(fieldID); v.add(new X9Curve(curve, seed)); v.add(new X9ECPoint(g)); v.add(new DERInteger(n)); if (!h.equals(BigInteger.valueOf(1))) { v.add(new DERInteger(h)); } return new DERSequence(v); }