List of usage examples for org.bouncycastle.asn1 DERUTF8String DERUTF8String
public DERUTF8String(String string)
From source file:br.gov.frameworkdemoiselle.certificate.signer.pkcs7.bc.attribute.BCSignerLocation.java
License:Open Source License
@Override public ASN1Set getValue() { SignerLocation attribute = (SignerLocation) super.getAttribute(); String localityName = attribute.getValue(); org.bouncycastle.asn1.esf.SignerLocation signerLocation = new org.bouncycastle.asn1.esf.SignerLocation( new DERUTF8String(""), new DERUTF8String(localityName), new DERSequence()); return new DERSet(signerLocation); }
From source file:ca.trustpoint.m2m.EntityNameAttribute.java
License:Apache License
/** * Returns the DER encoding of this instance. * * @return The DER encoding of this instance. * @throws IOException if this instance cannot be encoded. *//*www . j av a 2 s.c om*/ public byte[] getEncoded() throws IOException { if (!isValid()) { throw new IOException("Attribute is not valid."); } ASN1Encodable encodedValue; switch (id) { case Country: case DistinguishedNameQualifier: case SerialNumber: encodedValue = new DERPrintableString(value); break; case Organization: case OrganizationalUnit: case StateOrProvince: case Locality: case CommonName: encodedValue = new DERUTF8String(value); break; case DomainComponent: encodedValue = new DERIA5String(value); break; case RegisteredId: encodedValue = new ASN1ObjectIdentifier(value); break; case OctetsName: encodedValue = new DEROctetString(Hex.decode(value)); break; default: throw new IOException("Unknown attribute type ID."); } return new DERTaggedObject(false, id.getIndexId(), encodedValue).getEncoded(); }
From source file:com.github.horrorho.inflatabledonkey.data.der.KeySet.java
License:Open Source License
ASN1Primitive toASN1Primitive(boolean includeChecksum) { DEROctetString checksumEncodable = includeChecksum ? new DEROctetString(checksum()) : null; ASN1Integer flagsEncodable = flags.map(ASN1Integer::new).orElse(null); ASN1EncodableVector vector = DER.vector(new DERUTF8String(name), DER.toSet(keys), DER.toSet(serviceKeyIDs), checksumEncodable, flagsEncodable, signatureInfo.orElse(null)); DERSequence sequence = new DERSequence(vector); return DER.toApplicationSpecific(APPLICATION_TAG, sequence); }
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 ww w .j a va 2s .c o 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.rcn.service.CertificateService.java
License:Open Source License
private GeneralNames toGeneralNames(String altName, Map<String, String> generalNameMap) { GeneralName subjectAltName = new GeneralName(GeneralName.rfc822Name, altName); List<GeneralName> generalNameList = new ArrayList<GeneralName>(); generalNameList.add(subjectAltName); generalNameMap.keySet().forEach(oid -> { String value = generalNameMap.get(oid); DERUTF8String derUtf8 = new DERUTF8String(value); ASN1Encodable oidObj = new DERObjectIdentifier(oid); ASN1Encodable valueObj = new DERTaggedObject(true, 0, derUtf8); ASN1Encodable[] asn1Seq = new ASN1Encodable[] { oidObj, valueObj }; generalNameList.add(new GeneralName(GeneralName.otherName, new DERSequence(asn1Seq))); });// w w w. j a v a2 s . c o m return new GeneralNames(new DERSequence(generalNameList.toArray(new GeneralName[0]))); }
From source file:com.vmware.identity.openidconnect.client.TestUtils.java
License:Open Source License
static X509Certificate generateCertificate(KeyPair keyPair, String dn, String subjectAltName) throws Exception { ContentSigner sigGen = new JcaContentSignerBuilder("SHA1withRSA").build(keyPair.getPrivate()); Date startDate = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000); Date endDate = new Date(System.currentTimeMillis() + 365 * 24 * 60 * 60 * 1000); X509v3CertificateBuilder v3CertGen = new JcaX509v3CertificateBuilder(new X500Name("CN=" + dn), new BigInteger(64, new SecureRandom()), startDate, endDate, new X500Name("CN=" + dn), keyPair.getPublic());// w w w .j a v a 2 s . c o m if (subjectAltName != null) { v3CertGen .addExtension(Extension.subjectAlternativeName, true, new GeneralNames(new GeneralName(GeneralName.otherName, new DERSequence(new ASN1Encodable[] { new DERObjectIdentifier("1.3.6.1.4.1.311.20.2.3"), new DERTaggedObject(true, 0, new DERUTF8String(subjectAltName)) })))); } X509CertificateHolder certHolder = v3CertGen.build(sigGen); X509Certificate x509Certificate = new JcaX509CertificateConverter().getCertificate(certHolder); return x509Certificate; }
From source file:com.vmware.identity.sts.auth.impl.UserCertAuthenticatorTest.java
License:Open Source License
private static X509Certificate generateCertificate(KeyPair keyPair, String dn) throws Exception { ContentSigner sigGen = new JcaContentSignerBuilder("SHA1withRSA").build(keyPair.getPrivate()); Date startDate = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000); Date endDate = new Date(System.currentTimeMillis() + 365 * 24 * 60 * 60 * 1000); X509v3CertificateBuilder v3CertGen = new JcaX509v3CertificateBuilder(new X500Name("CN=" + dn), new BigInteger(64, new SecureRandom()), startDate, endDate, new X500Name("CN=" + dn), keyPair.getPublic());/*from w w w . ja v a 2s . c o m*/ v3CertGen.addExtension(Extension.subjectAlternativeName, true, new GeneralNames(new GeneralName(GeneralName.otherName, new DERSequence(new ASN1Encodable[] { new DERObjectIdentifier("1.3.6.1.4.1.311.20.2.3"), new DERTaggedObject(true, 0, new DERUTF8String(upn)) })))); X509CertificateHolder certHolder = v3CertGen.build(sigGen); X509Certificate x509Certificate = new JcaX509CertificateConverter().getCertificate(certHolder); return x509Certificate; }
From source file:com.vvote.thirdparty.ximix.util.SubjectPublicKeyInfoFactory.java
License:Apache License
/** * Return a SubjectPublicKeyInfo object containing an encoding of BLS public key. * * @param keyParameters the public key to be encoded. * @return a SubjectPublicKeyInfo object containing the public key. * @throws java.io.IOException if the public key cannot be encoded. *///from w ww . j av a 2 s .c o m public static SubjectPublicKeyInfo createSubjectPublicKeyInfo(BLS01PublicKeyParameters keyParameters) throws IOException { return new SubjectPublicKeyInfo( new AlgorithmIdentifier(XimixObjectIdentifiers.ximixAlgorithmsExperimental, new DERSequence(new ASN1Encodable[] { new DERUTF8String(keyParameters.getParameters().getCurveParameters().toString()), new DEROctetString(keyParameters.getParameters().getG().toBytes()) })), keyParameters.getPk().toBytes()); }
From source file:de.fichtelmax.asn1.ASN1PrinterTest.java
License:Open Source License
@Test public void printSequence() throws IOException { String text = "Hello World!"; String oid = "1.2.3.45.10982345"; long number = 12345678901l; DERUTF8String string = new DERUTF8String(text); DERObjectIdentifier objectIdentifier = new DERObjectIdentifier(oid); DERInteger integer = new DERInteger(number); DERSet set = new DERSet(new ASN1Encodable[] { objectIdentifier, integer }); DERSequence sequence = new DERSequence(new ASN1Encodable[] { string, set }); cut.print(sequence.getEncoded());/*from ww w . ja v a 2s . c om*/ verify(out).println(contains(text)); verify(out).println(contains(oid)); verify(out).println(contains(Long.toString(number))); }
From source file:de.fichtelmax.asn1.ber.BERParserTest.java
License:Open Source License
@Test public void utf8String() throws IOException { String text = "something"; DERUTF8String utf8String = new DERUTF8String(text); BERObject berObject = cut.parse(utf8String.getEncoded()); assertThat(berObject.getValue(), is(equalTo(text.getBytes("UTF-8")))); }