public static X9ECParameters getByName( String name) { ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)objIds.get(Strings.toUpperCase(name)); if (oid != null) { return getByOID(oid); } return null; }
private ASN1ObjectIdentifier[] getExtensionOIDs(boolean isCritical) { Vector oidVec = new Vector(); for (int i = 0; i != ordering.size(); i++) { Object oid = ordering.elementAt(i); if (((X509Extension)extensions.get(oid)).isCritical() == isCritical) { oidVec.addElement(oid); } } return toOidArray(oidVec); }
/** * Creates a new <code>PolicyMappings</code> instance. * * @param mappings a <code>HashMap</code> value that maps * <code>String</code> oids * to other <code>String</code> oids. * @deprecated use CertPolicyId constructors. */ public PolicyMappings(Hashtable mappings) { ASN1EncodableVector dev = new ASN1EncodableVector(); Enumeration it = mappings.keys(); while (it.hasMoreElements()) { String idp = (String)it.nextElement(); String sdp = (String)mappings.get(idp); ASN1EncodableVector dv = new ASN1EncodableVector(); dv.add(new ASN1ObjectIdentifier(idp)); dv.add(new ASN1ObjectIdentifier(sdp)); dev.add(new DERSequence(dv)); } seq = new DERSequence(dev); }
public static X9ECParameters getNamedCurveByOid( ASN1ObjectIdentifier oid) { X9ECParameters params = X962NamedCurves.getByOID(oid); if (params == null) { params = SECNamedCurves.getByOID(oid); if (params == null) { params = NISTNamedCurves.getByOID(oid); } if (params == null) { params = TeleTrusTNamedCurves.getByOID(oid); } } return params; }
public PublicKey generatePublic(SubjectPublicKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getAlgorithm().getAlgorithm(); if (algOid.equals(PKCSObjectIdentifiers.dhKeyAgreement)) { return new BCDHPublicKey(keyInfo); } else if (algOid.equals(X9ObjectIdentifiers.dhpublicnumber)) { return new BCDHPublicKey(keyInfo); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
AlgorithmParameterGenerator createAlgorithmParameterGenerator(ASN1ObjectIdentifier algorithm) throws GeneralSecurityException { String algorithmName = (String)BASE_CIPHER_NAMES.get(algorithm); if (algorithmName != null) { try { // this is reversed as the Sun policy files now allow unlimited strength RSA return helper.createAlgorithmParameterGenerator(algorithmName); } catch (NoSuchAlgorithmException e) { // Ignore } } return helper.createAlgorithmParameterGenerator(algorithm.getId()); }
private java.security.cert.Certificate readDERCertificate( ASN1InputStream dIn) throws IOException, CertificateParsingException { ASN1Sequence seq = (ASN1Sequence)dIn.readObject(); if (seq.size() > 1 && seq.getObjectAt(0) instanceof ASN1ObjectIdentifier) { if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) { sData = SignedData.getInstance(ASN1Sequence.getInstance( (ASN1TaggedObject)seq.getObjectAt(1), true)).getCertificates(); return getCertificate(); } } return new X509CertificateObject( Certificate.getInstance(seq)); }
private void setPrivateData(ASN1InputStream cha) throws IOException { ASN1Primitive obj; obj = cha.readObject(); if (obj instanceof ASN1ObjectIdentifier) { this.oid = (ASN1ObjectIdentifier)obj; } else { throw new IllegalArgumentException("no Oid in CerticateHolderAuthorization"); } obj = cha.readObject(); if (obj instanceof DERApplicationSpecific) { this.accessRights = (DERApplicationSpecific)obj; } else { throw new IllegalArgumentException("No access rights in CerticateHolderAuthorization"); } }
/** * Return a new table with the passed in attribute added. * * @param attrType * @param attrValue * @return */ public AttributeTable add(ASN1ObjectIdentifier attrType, ASN1Encodable attrValue) { AttributeTable newTable = new AttributeTable(attributes); newTable.addAttribute(attrType, new Attribute(attrType, new DERSet(attrValue))); return newTable; }
public byte[] getExtensionValue(String oid) { Extension ext = getExtension(new ASN1ObjectIdentifier(oid)); if (ext != null) { try { return ext.getExtnValue().getEncoded(); } catch (Exception e) { throw new RuntimeException("error encoding " + e.toString()); } } return null; }
private static byte[] calculatePbeMac( ASN1ObjectIdentifier oid, byte[] salt, int itCount, char[] password, boolean wrongPkcs12Zero, byte[] data) throws Exception { SecretKeyFactory keyFact = SecretKeyFactory.getInstance(oid.getId(), bcProvider); PBEParameterSpec defParams = new PBEParameterSpec(salt, itCount); PBEKeySpec pbeSpec = new PBEKeySpec(password); BCPBEKey key = (BCPBEKey)keyFact.generateSecret(pbeSpec); key.setTryWrongPKCS12Zero(wrongPkcs12Zero); Mac mac = Mac.getInstance(oid.getId(), bcProvider); mac.init(key, defParams); mac.update(data); return mac.doFinal(); }
static CipherParameters createCipherParameters(ASN1ObjectIdentifier algorithm, ExtendedDigest digest, int blockSize, PKCS12PBEParams pbeParams, char[] password) { PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(digest); pGen.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password), pbeParams.getIV(), pbeParams.getIterations().intValue()); CipherParameters params; if (PKCS12PBEUtils.hasNoIv(algorithm)) { params = pGen.generateDerivedParameters(PKCS12PBEUtils.getKeySize(algorithm)); } else { params = pGen.generateDerivedParameters(PKCS12PBEUtils.getKeySize(algorithm), blockSize * 8); if (PKCS12PBEUtils.isDesAlg(algorithm)) { DESedeParameters.setOddParity(((KeyParameter)((ParametersWithIV)params).getParameters()).getKey()); } } return params; }
/** * Add multiple key agreement based recipients (sharing a single KeyAgreeRecipientInfo structure). * * @deprecated use the addRecipientGenerator and JceKeyAgreeRecipientInfoGenerator * @param agreementAlgorithm key agreement algorithm to use. * @param senderPrivateKey private key to initialise sender side of agreement with. * @param senderPublicKey sender public key to include with message. * @param recipientCerts recipients' public key certificates. * @param cekWrapAlgorithm OID for key wrapping algorithm to use. * @param provider provider to use for the agreement calculation. * @exception NoSuchAlgorithmException if the algorithm requested cannot be found * @exception InvalidKeyException if the keys are inappropriate for the algorithm specified */ public void addKeyAgreementRecipients( String agreementAlgorithm, PrivateKey senderPrivateKey, PublicKey senderPublicKey, Collection recipientCerts, String cekWrapAlgorithm, Provider provider) throws NoSuchAlgorithmException, InvalidKeyException { JceKeyAgreeRecipientInfoGenerator recipientInfoGenerator = new JceKeyAgreeRecipientInfoGenerator(new ASN1ObjectIdentifier(agreementAlgorithm), senderPrivateKey, senderPublicKey, new ASN1ObjectIdentifier(cekWrapAlgorithm)).setProvider(provider); for (Iterator it = recipientCerts.iterator(); it.hasNext();) { try { recipientInfoGenerator.addRecipient((X509Certificate)it.next()); } catch (CertificateEncodingException e) { throw new IllegalArgumentException("unable to encode certificate: " + e.getMessage()); } } oldRecipientInfoGenerators.add(recipientInfoGenerator); }
public ASN1EncodableVector getASN1EncodableVector(ASN1ObjectIdentifier oid, boolean publicPointOnly) { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(oid); if (!publicPointOnly) { v.add(new UnsignedInteger(0x01, getPrimeModulusP())); v.add(new UnsignedInteger(0x02, getFirstCoefA())); v.add(new UnsignedInteger(0x03, getSecondCoefB())); v.add(new DERTaggedObject(false, 0x04, new DEROctetString(getBasePointG()))); v.add(new UnsignedInteger(0x05, getOrderOfBasePointR())); } v.add(new DERTaggedObject(false, 0x06, new DEROctetString(getPublicPointY()))); if (!publicPointOnly) { v.add(new UnsignedInteger(0x07, getCofactorF())); } return v; }
AlgorithmIdentifier getAlgorithmIdentifier(ASN1ObjectIdentifier encryptionOID, AlgorithmParameters params) throws CMSException { ASN1Encodable asn1Params; if (params != null) { try { asn1Params = ASN1Primitive.fromByteArray(params.getEncoded("ASN.1")); } catch (IOException e) { throw new CMSException("cannot encode parameters: " + e.getMessage(), e); } } else { asn1Params = DERNull.INSTANCE; } return new AlgorithmIdentifier( encryptionOID, asn1Params); }
private McElieceCCA2PrivateKey(ASN1Sequence seq) { oid = ((ASN1ObjectIdentifier)seq.getObjectAt(0)); BigInteger bigN = ((ASN1Integer)seq.getObjectAt(1)).getValue(); n = bigN.intValue(); BigInteger bigK = ((ASN1Integer)seq.getObjectAt(2)).getValue(); k = bigK.intValue(); encField = ((ASN1OctetString)seq.getObjectAt(3)).getOctets(); encGp = ((ASN1OctetString)seq.getObjectAt(4)).getOctets(); encP = ((ASN1OctetString)seq.getObjectAt(5)).getOctets(); encH = ((ASN1OctetString)seq.getObjectAt(6)).getOctets(); ASN1Sequence asnQInv = (ASN1Sequence)seq.getObjectAt(7); encqInv = new byte[asnQInv.size()][]; for (int i = 0; i < asnQInv.size(); i++) { encqInv[i] = ((ASN1OctetString)asnQInv.getObjectAt(i)).getOctets(); } }
private Set convert(Set orig) { if (orig == null) { return orig; } Set con = new HashSet(orig.size()); for (Iterator it = orig.iterator(); it.hasNext();) { Object o = it.next(); if (o instanceof String) { con.add(new ASN1ObjectIdentifier((String)o)); } else { con.add(o); } } return con; }
private McElieceCCA2PublicKey(ASN1Sequence seq) { oid = ((ASN1ObjectIdentifier)seq.getObjectAt(0)); BigInteger bigN = ((ASN1Integer)seq.getObjectAt(1)).getValue(); n = bigN.intValue(); BigInteger bigT = ((ASN1Integer)seq.getObjectAt(2)).getValue(); t = bigT.intValue(); matrixG = ((ASN1OctetString)seq.getObjectAt(3)).getOctets(); }
/** * return the X9ECParameters object for the named curve represented by * the passed in object identifier. Null if the curve isn't present. * * @param oid an object identifier representing a named curve, if present. */ public static X9ECParameters getByOID( ASN1ObjectIdentifier oid) { X9ECParametersHolder holder = (X9ECParametersHolder)curves.get(oid); if (holder != null) { return holder.getParameters(); } return null; }
public ContentHints( ASN1ObjectIdentifier contentType, DERUTF8String contentDescription) { this.contentType = contentType; this.contentDescription = contentDescription; }
/** * generate an enveloped object that contains an CMS Enveloped Data * object using the given encryptor and marking the data as being of the passed * in type. */ public OutputStream open( ASN1ObjectIdentifier dataType, OutputStream out, OutputEncryptor encryptor) throws CMSException, IOException { return doOpen(dataType, out, encryptor); }
protected PasswordRecipientInfoGenerator(ASN1ObjectIdentifier kekAlgorithm, char[] password, int keySize, int blockSize) { this.password = password; this.schemeID = PasswordRecipient.PKCS5_SCHEME2_UTF8; this.kekAlgorithm = kekAlgorithm; this.keySize = keySize; this.blockSize = blockSize; }
public SafeBag( ASN1ObjectIdentifier oid, ASN1Encodable obj) { this.bagId = oid; this.bagValue = obj; this.bagAttributes = null; }
/** * Returns the digest algorithm ID if an object digest info is used. * * @return The digest algorithm ID or <code>null</code> if no object * digest info is set. */ public ASN1ObjectIdentifier getOtherObjectTypeID() { if (holder.getObjectDigestInfo() != null) { new ASN1ObjectIdentifier(holder.getObjectDigestInfo().getOtherObjectTypeID().getId()); } return null; }
/** * Creates a new <code>PolicyQualifierInfo</code> instance. * * @param policyQualifierId a <code>PolicyQualifierId</code> value * @param qualifier the qualifier, defined by the above field. */ public PolicyQualifierInfo( ASN1ObjectIdentifier policyQualifierId, ASN1Encodable qualifier) { this.policyQualifierId = policyQualifierId; this.qualifier = qualifier; }
private static int getKeySize(ASN1ObjectIdentifier kekAlgorithm) { Integer size = (Integer)PasswordRecipientInformation.KEYSIZES.get(kekAlgorithm); if (size == null) { throw new IllegalArgumentException("cannot find key size for algorithm: " + kekAlgorithm); } return size.intValue(); }
/** * @deprecated use open(out, MacCalculator) */ public OutputStream open( OutputStream out, String encryptionOID, Provider provider) throws NoSuchAlgorithmException, CMSException, IOException { convertOldRecipients(rand, provider); return open(out, new JceCMSMacCalculatorBuilder(new ASN1ObjectIdentifier(encryptionOID)).setSecureRandom(rand).setProvider(provider).build()); }
public static ASN1ObjectIdentifier getHashAlg(String hashAlgName) throws NoSuchAlgorithmException { ParamUtil.requireNonNull("hashAlgName", hashAlgName); HashAlgoType hashAlgo = HashAlgoType.getHashAlgoType(hashAlgName.toUpperCase()); if (hashAlgo == null) { throw new NoSuchAlgorithmException("Unsupported hash algorithm " + hashAlgName); } return hashAlgo.oid(); }
private KeyPairWithSubjectPublicKeyInfo genECKeypair(String curveNameOrOid, SecureRandom random) throws Exception { ASN1ObjectIdentifier curveOid = AlgorithmUtil.getCurveOidForCurveNameOrOid(curveNameOrOid); if (curveOid == null) { throw new IllegalArgumentException("invalid curveNameOrOid '" + curveNameOrOid + "'"); } KeyPair kp = KeyUtil.generateECKeypair(curveOid, random); AlgorithmIdentifier algId = new AlgorithmIdentifier( X9ObjectIdentifiers.id_ecPublicKey, curveOid); BCECPublicKey pub = (BCECPublicKey) kp.getPublic(); byte[] keyData = pub.getQ().getEncoded(false); SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algId, keyData); return new KeyPairWithSubjectPublicKeyInfo(kp, subjectPublicKeyInfo); }
public Set getCriticalExtensionOIDs() { if (this.getVersion() == 3) { Set set = new HashSet(); Extensions extensions = c.getTBSCertificate().getExtensions(); if (extensions != null) { Enumeration e = extensions.oids(); while (e.hasMoreElements()) { ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)e.nextElement(); Extension ext = extensions.getExtension(oid); if (ext.isCritical()) { set.add(oid.getId()); } } return set; } } return null; }
public PrivateKey generatePrivate(PrivateKeyInfo keyInfo) throws IOException { ASN1ObjectIdentifier algOid = keyInfo.getPrivateKeyAlgorithm().getAlgorithm(); if (algOid.equals(X9ObjectIdentifiers.id_ecPublicKey)) { return new BCECPrivateKey(algorithm, keyInfo, configuration); } else { throw new IOException("algorithm identifier " + algOid + " in key not recognised"); } }
/** * Look up the extension associated with the passed in OID. * * @param oid the OID of the extension of interest. * * @return the extension if present, null otherwise. */ public Extension getExtension(ASN1ObjectIdentifier oid) { if (extensions != null) { return extensions.getExtension(oid); } return null; }
/** * Return the first attribute matching the OBJECT IDENTIFIER oid. * * @param oid type of attribute required. * @return first attribute found of type oid. */ public Attribute get( ASN1ObjectIdentifier oid) { Object value = attributes.get(oid); if (value instanceof Vector) { return (Attribute)((Vector)value).elementAt(0); } return (Attribute)value; }
private static void addOidNameMap(Map<ASN1ObjectIdentifier, String> oidNameMap, Map<String, ASN1ObjectIdentifier> nameOidMap, ASN1ObjectIdentifier oid, String... names) { oidNameMap.put(oid, names[0].toUpperCase()); nameOidMap.put(oid.getId(), oid); for (String name : names) { nameOidMap.put(name.toUpperCase(), oid); } }
public ASN1Encodable stringToValue(ASN1ObjectIdentifier oid, String value) { if (value.length() != 0 && value.charAt(0) == '#') { try { return IETFUtils.valueFromHexString(value, 1); } catch (IOException e) { throw new RuntimeException("can't recode value for oid " + oid.getId()); } } else { if (value.length() != 0 && value.charAt(0) == '\\') { value = value.substring(1); } if (oid.equals(EmailAddress) || oid.equals(DC)) { return new DERIA5String(value); } else if (oid.equals(DATE_OF_BIRTH)) // accept time string as well as # (for compatibility) { return new ASN1GeneralizedTime(value); } else if (oid.equals(C) || oid.equals(SN) || oid.equals(DN_QUALIFIER) || oid.equals(TELEPHONE_NUMBER)) { return new DERPrintableString(value); } } return new DERUTF8String(value); }
private void addDigestSignature( ConfigurableProvider provider, String digest, String className, ASN1ObjectIdentifier oid) { String mainName = digest + "WITHRSA"; String jdk11Variation1 = digest + "withRSA"; String jdk11Variation2 = digest + "WithRSA"; String alias = digest + "/" + "RSA"; String longName = digest + "WITHRSAENCRYPTION"; String longJdk11Variation1 = digest + "withRSAEncryption"; String longJdk11Variation2 = digest + "WithRSAEncryption"; provider.addAlgorithm("Signature." + mainName, className); provider.addAlgorithm("Alg.Alias.Signature." + jdk11Variation1, mainName); provider.addAlgorithm("Alg.Alias.Signature." + jdk11Variation2, mainName); provider.addAlgorithm("Alg.Alias.Signature." + longName, mainName); provider.addAlgorithm("Alg.Alias.Signature." + longJdk11Variation1, mainName); provider.addAlgorithm("Alg.Alias.Signature." + longJdk11Variation2, mainName); provider.addAlgorithm("Alg.Alias.Signature." + alias, mainName); if (oid != null) { provider.addAlgorithm("Alg.Alias.Signature." + oid, mainName); provider.addAlgorithm("Alg.Alias.Signature.OID." + oid, mainName); } }
private static int getKeySize(ASN1ObjectIdentifier oid) { Integer size = (Integer)keySizes.get(oid); if (size != null) { return size.intValue(); } return -1; }
/** * create an AuthorityInformationAccess with the oid and location provided. */ public AuthorityInformationAccess( ASN1ObjectIdentifier oid, GeneralName location) { descriptions = new AccessDescription[1]; descriptions[0] = new AccessDescription(oid, location); }