List of usage examples for org.bouncycastle.asn1 DERInteger getValue
public BigInteger getValue()
From source file:ElGamalPrivatePGKey.java
License:Open Source License
public ElGamalPrivatePGKey(PrivateKeyInfo info) { ElGamalParameter params = new ElGamalParameter((ASN1Sequence) info.getAlgorithmId().getParameters()); DERInteger derX = (DERInteger) info.getPrivateKey(); this.x = derX.getValue(); this.elSpec = new ElGamalParameterSpec(params.getP(), params.getG()); }
From source file:ElGamalPublicPGKey.java
License:Open Source License
public ElGamalPublicPGKey(SubjectPublicKeyInfo info) { ElGamalParameter params = new ElGamalParameter((ASN1Sequence) info.getAlgorithmId().getParameters()); DERInteger derY = null; try {//from www. j a v a2s. c o m derY = (DERInteger) info.getPublicKey(); } catch (IOException e) { throw new IllegalArgumentException("invalid info structure in DSA public key"); } this.y = derY.getValue(); this.elSpec = new ElGamalParameterSpec(params.getP(), params.getG()); }
From source file:com.jlocksmith.util.ExtensionUtil.java
License:Open Source License
/** * Convert To Hex String/* w ww . j a v a 2 s . c o m*/ * * @param derInt * * @return String */ private static String convertToHexString(DERInteger derInt) { String sHexCrlNumber = derInt.getValue().toString(16).toUpperCase(); StringBuffer strBuff = new StringBuffer(); for (int i = 0; i < sHexCrlNumber.length(); i++) { strBuff.append(sHexCrlNumber.charAt(i)); if ((((i + 1) % 4) == 0) && ((i + 1) != sHexCrlNumber.length())) { strBuff.append(' '); } } return strBuff.toString(); }
From source file:com.jlocksmith.util.ExtensionUtil.java
License:Open Source License
/** * Get Basic Constraints String Value/* w w w.j a v a2 s .co m*/ * * @param bytes * * @return String * * @throws IOException */ private String getBasicConstraintsStringValue(byte[] bytes) throws IOException { // Get sequence ASN1Sequence asn1Seq = (ASN1Sequence) toDERObject(bytes); int aLen = asn1Seq.size(); // Default values when none specified in sequence boolean bCa = false; int iPathLengthConstraint = -1; // Read CA boolean if present in sequence if (aLen > 0) { DERBoolean derBool = (DERBoolean) asn1Seq.getObjectAt(0); bCa = derBool.isTrue(); } // Read Path Length Constraint boolean if present in sequence if (aLen > 1) { DERInteger derInt = (DERInteger) asn1Seq.getObjectAt(1); iPathLengthConstraint = derInt.getValue().intValue(); } // Output information StringBuffer strBuff = new StringBuffer(); strBuff.append(localeUtil.getString(bCa ? "SubjectIsCa" : "SubjectIsNotCa")); strBuff.append('\n'); // Path length constraint (only has meaning when CA is true) if (iPathLengthConstraint != -1 && bCa) { strBuff.append(MessageFormat.format(localeUtil.getString("PathLengthConstraint"), new Object[] { "" + iPathLengthConstraint })); } else { strBuff.append(localeUtil.getString("NoPathLengthConstraint")); } strBuff.append('\n'); return strBuff.toString(); }
From source file:com.jlocksmith.util.ExtensionUtil.java
License:Open Source License
/** * Get Policy Constraints String Value// www . ja v a2 s . c o m * * @param bytes * * @return String * * @throws IOException */ private String getPolicyConstraintsStringValue(byte[] bytes) throws IOException { ASN1Sequence policyConstraints = (ASN1Sequence) toDERObject(bytes); StringBuffer strBuff = new StringBuffer(); for (int i = 0, len = policyConstraints.size(); i < len; i++) { DERTaggedObject policyConstraint = (DERTaggedObject) policyConstraints.getObjectAt(i); DERInteger skipCerts = new DERInteger(((DEROctetString) policyConstraint.getObject()).getOctets()); int iSkipCerts = skipCerts.getValue().intValue(); switch (policyConstraint.getTagNo()) { case 0: strBuff.append(MessageFormat.format(localeUtil.getString("RequireExplicitPolicy"), new Object[] { "" + iSkipCerts })); strBuff.append('\n'); break; case 1: strBuff.append(MessageFormat.format(localeUtil.getString("InhibitPolicyMapping"), new Object[] { "" + iSkipCerts })); strBuff.append('\n'); break; } } return strBuff.toString(); }
From source file:com.jlocksmith.util.ExtensionUtil.java
License:Open Source License
/** * Get Inhibit Any Policy String Value// w w w .ja v a2 s. com * * @param bytes * @return * @throws IOException */ private String getInhibitAnyPolicyStringValue(byte[] bytes) throws IOException { DERInteger skipCerts = (DERInteger) toDERObject(bytes); int iSkipCerts = skipCerts.getValue().intValue(); StringBuffer strBuff = new StringBuffer(); strBuff.append( MessageFormat.format(localeUtil.getString("InhibitAnyPolicy"), new Object[] { "" + iSkipCerts })); strBuff.append('\n'); return strBuff.toString(); }
From source file:com.jlocksmith.util.ExtensionUtil.java
License:Open Source License
/** * Get Microsoft Certificate Template V2 String Value * /*from w w w .ja v a2 s. c o m*/ * @param bytes * @return String * @throws IOException */ private String getMicrosoftCertificateTemplateV2StringValue(byte[] bytes) throws IOException { ASN1Sequence seq = (ASN1Sequence) toDERObject(bytes); StringBuffer sb = new StringBuffer(); sb.append(MessageFormat.format(localeUtil.getString("MsftCertTemplateId"), new Object[] { ((DERObjectIdentifier) seq.getObjectAt(0)).getId() })); sb.append('\n'); DERInteger derInt = (DERInteger) seq.getObjectAt(1); sb.append(MessageFormat.format(localeUtil.getString("MsftCertTemplateMajorVer"), new Object[] { derInt.getValue().toString() })); sb.append('\n'); if ((derInt = (DERInteger) seq.getObjectAt(2)) != null) { sb.append(MessageFormat.format(localeUtil.getString("MsftCertTemplateMinorVer"), new Object[] { derInt.getValue().toString() })); sb.append('\n'); } return sb.toString(); }
From source file:com.jlocksmith.util.ExtensionUtil.java
License:Open Source License
/** * Get Novell Quality Attr//from w w w .j a v a 2s. co m * * @param seq * * @return CharSequence */ private CharSequence getNovellQualityAttr(ASN1Sequence seq) { StringBuffer res = new StringBuffer(); boolean enforceQuality = ((DERBoolean) seq.getObjectAt(0)).isTrue(); res.append("\t\t").append(localeUtil.getString("NovellQualityEnforce")); res.append(' ').append(enforceQuality).append('\n'); ASN1Sequence compusecQ = (ASN1Sequence) seq.getObjectAt(1); int clen = compusecQ.size(); if (clen > 0) { res.append("\t\t"); res.append(localeUtil.getString("NovellCompusecQuality")); res.append('\n'); } for (int i = 0; i < clen; i++) { ASN1Sequence cqPair = (ASN1Sequence) compusecQ.getObjectAt(i); DERInteger tmp = (DERInteger) cqPair.getObjectAt(0); long type = tmp.getValue().longValue(); String csecCriteria = getResource("NovellCompusecQuality." + type, "UnrecognisedNovellCompusecQuality"); csecCriteria = MessageFormat.format(csecCriteria, new Object[] { tmp.getValue() }); res.append("\t\t\t").append(csecCriteria); tmp = (DERInteger) cqPair.getObjectAt(1); String csecRating; if (type == 1L) { // TCSEC csecRating = getResource("TCSECRating." + tmp.getValue(), "UnrecognisedTCSECRating"); } else { csecRating = localeUtil.getString("UnrecognisedNovellQualityRating"); } csecRating = MessageFormat.format(csecRating, new Object[] { tmp.getValue() }); res.append("\n\t\t\t\t").append(localeUtil.getString("NovellQualityRating")); res.append(' ').append(csecRating).append('\n'); } res.append("\t\t").append(localeUtil.getString("NovellCryptoQuality")); res.append(' ').append(localeUtil.getString("DecodeNotImplemented")); res.append('\n'); String ksqv = ((DERInteger) seq.getObjectAt(3)).getValue().toString(); String ksq = getResource("NovellKeyStorageQuality." + ksqv, "UnrecognisedNovellKeyStorageQuality"); res.append("\t\t").append(localeUtil.getString("NovellKeyStorageQuality")); res.append("\n\t\t\t").append(MessageFormat.format(ksq, new Object[] { ksqv })); res.append('\n'); return res; }
From source file:com.oneis.common.utils.SSLCertificates.java
License:Mozilla Public License
private static PrivateKey readPEMPrivateKey(String filename) throws java.io.IOException, java.security.GeneralSecurityException { ByteArrayInputStream bIn = readPEM(filename); ASN1InputStream aIn = new ASN1InputStream(bIn); ASN1Sequence seq = (ASN1Sequence) aIn.readObject(); if (!(seq.getObjectAt(1) instanceof DERInteger)) { throw new RuntimeException("Can't read RSA private key from " + filename + " - if file starts '-----BEGIN PRIVATE KEY-----' then it needs converting to RSA format with 'openssl rsa -in server-in.key -out server.key'."); }/*from w w w . j ava 2 s . c o m*/ DERInteger mod = (DERInteger) seq.getObjectAt(1); DERInteger pubExp = (DERInteger) seq.getObjectAt(2); DERInteger privExp = (DERInteger) seq.getObjectAt(3); DERInteger p1 = (DERInteger) seq.getObjectAt(4); DERInteger p2 = (DERInteger) seq.getObjectAt(5); DERInteger exp1 = (DERInteger) seq.getObjectAt(6); DERInteger exp2 = (DERInteger) seq.getObjectAt(7); DERInteger crtCoef = (DERInteger) seq.getObjectAt(8); RSAPrivateCrtKeySpec privSpec = new RSAPrivateCrtKeySpec(mod.getValue(), pubExp.getValue(), privExp.getValue(), p1.getValue(), p2.getValue(), exp1.getValue(), exp2.getValue(), crtCoef.getValue()); KeyFactory factory = KeyFactory.getInstance("RSA"); return factory.generatePrivate(privSpec); }
From source file:de.fraunhofer.fokus.openeid.ca.ChipAuthenticationDomainParameterInfo.java
License:Open Source License
public ChipAuthenticationDomainParameterInfo(DERSequence chipDomainParameterInfoSequence) throws InvalidDomainParameter { DERObjectIdentifier derOid = (DERObjectIdentifier) chipDomainParameterInfoSequence.getObjectAt(0); protocolOid = derOid.getId();//from ww w . j a v a2s. c om DERSequence algorithm = (DERSequence) chipDomainParameterInfoSequence.getObjectAt(1); AlgorithmIdentifier id = new AlgorithmIdentifier(algorithm); int domainParameterValue = ((DERInteger) id.getParameter().get(0)).getValue().intValue(); domainParameter = StandardizedDomainParameters.getById(domainParameterValue); DERInteger derKeyId = (DERInteger) chipDomainParameterInfoSequence.getObjectAt(2); keyId = derKeyId.getValue().intValue(); }