org.bouncycastle.operator.OperatorException Java Examples
The following examples show how to use
org.bouncycastle.operator.OperatorException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TlsResourceBuilder.java From qpid-broker-j with Apache License 2.0 | 6 votes |
private static X509Certificate createSelfSignedCertificate(final KeyPair keyPair, final String dn, final ValidityPeriod period, final AlternativeName... alternativeName) throws CertificateException { try { final X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder( new X500Name(RFC4519Style.INSTANCE, dn), generateSerialNumber(), new Date(period.getFrom().toEpochMilli()), new Date(period.getTo().toEpochMilli()), new X500Name(RFC4519Style.INSTANCE, dn), keyPair.getPublic()); builder.addExtension(Extension.basicConstraints, false, new BasicConstraints(false)); builder.addExtension(createKeyUsageExtension()); builder.addExtension(createSubjectKeyExtension(keyPair.getPublic())); builder.addExtension(createAlternateNamesExtension(alternativeName)); return buildX509Certificate(builder, keyPair.getPrivate()); } catch (OperatorException | IOException e) { throw new CertificateException(e); } }
Example #2
Source File: TlsResourceBuilder.java From qpid-broker-j with Apache License 2.0 | 6 votes |
private static X509Certificate createRootCACertificate(final KeyPair keyPair, final String dn, final ValidityPeriod validityPeriod) throws CertificateException { try { final X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder( new X500Name(RFC4519Style.INSTANCE, dn), generateSerialNumber(), new Date(validityPeriod.getFrom().toEpochMilli()), new Date(validityPeriod.getTo().toEpochMilli()), new X500Name(RFC4519Style.INSTANCE, dn), keyPair.getPublic()); builder.addExtension(Extension.basicConstraints, false, new BasicConstraints(true)); builder.addExtension(createSubjectKeyExtension(keyPair.getPublic())); builder.addExtension(createAuthorityKeyExtension(keyPair.getPublic())); return buildX509Certificate(builder, keyPair.getPrivate()); } catch (OperatorException | IOException e) { throw new CertificateException(e); } }
Example #3
Source File: OcspClientBouncyCastle.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Generates an OCSP request using BouncyCastle. * @param issuerCert certificate of the issues * @param serialNumber serial number * @return an OCSP request * @throws OCSPException * @throws IOException */ private static OCSPReq generateOCSPRequest(X509Certificate issuerCert, BigInteger serialNumber) throws OCSPException, IOException, OperatorException, CertificateEncodingException { //Add provider BC Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); JcaDigestCalculatorProviderBuilder digestCalculatorProviderBuilder = new JcaDigestCalculatorProviderBuilder(); DigestCalculatorProvider digestCalculatorProvider = digestCalculatorProviderBuilder.build(); DigestCalculator digestCalculator = digestCalculatorProvider.get(CertificateID.HASH_SHA1); // Generate the id for the certificate we are looking for CertificateID id = new CertificateID(digestCalculator, new JcaX509CertificateHolder(issuerCert), serialNumber); // basic request generation with nonce OCSPReqBuilder gen = new OCSPReqBuilder(); gen.addRequest(id); // create details for nonce extension Extension ext = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false, new DEROctetString(new DEROctetString(PdfEncryption.createDocumentId()).getEncoded())); gen.setRequestExtensions(new Extensions(new Extension[]{ext})); return gen.build(); }
Example #4
Source File: TlsResourceBuilder.java From qpid-broker-j with Apache License 2.0 | 5 votes |
private static X509Certificate generateIntermediateCertificate(final KeyPair keyPair, final KeyCertificatePair rootCA, final String dn, final ValidityPeriod validityPeriod, final String crlUri) throws CertificateException { try { final X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder( rootCA.getCertificate(), generateSerialNumber(), new Date(validityPeriod.getFrom().toEpochMilli()), new Date(validityPeriod.getTo().toEpochMilli()), new X500Name(RFC4519Style.INSTANCE, dn), keyPair.getPublic()); //builder.addExtension(Extension.keyUsage, false, new KeyUsage(KeyUsage.keyCertSign)); builder.addExtension(Extension.basicConstraints, false, new BasicConstraints(true)); builder.addExtension(createSubjectKeyExtension(keyPair.getPublic())); builder.addExtension(createAuthorityKeyExtension(rootCA.getCertificate().getPublicKey())); if (crlUri != null) { builder.addExtension(createDistributionPointExtension(crlUri)); } return buildX509Certificate(builder, rootCA.getPrivateKey()); } catch (OperatorException | IOException e) { throw new CertificateException(e); } }
Example #5
Source File: TimestampToken.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
private SignerInformationVerifier getSignerInformationVerifier(final CertificateToken candidate) { try { final JcaSimpleSignerInfoVerifierBuilder verifier = new JcaSimpleSignerInfoVerifierBuilder(); verifier.setProvider(DSSSecurityProvider.getSecurityProviderName()); return verifier.build(candidate.getCertificate()); } catch (OperatorException e) { throw new DSSException("Unable to build an instance of SignerInformationVerifier", e); } }
Example #6
Source File: CrmfKeyWrapper.java From xipki with Apache License 2.0 | 5 votes |
@Override public byte[] generateWrappedKey(byte[] encryptionKey) throws OperatorException { try { Cipher cipher = Cipher.getInstance("RSA/NONE/OAEPPADDING", "BC"); cipher.init(Cipher.ENCRYPT_MODE, publicKey); return cipher.doFinal(encryptionKey); } catch (Exception ex) { throw new OperatorException("error in generateWrappedKey", ex); } }
Example #7
Source File: CrmfKeyWrapper.java From xipki with Apache License 2.0 | 4 votes |
/** * Encrypt the key with the following output. * <pre> * ECIES-Ciphertext-Value ::= SEQUENCE { * ephemeralPublicKey ECPoint, * symmetricCiphertext OCTET STRING, * macTag OCTET STRING * } * * ECPoint ::= OCTET STRING * </pre> */ @Override public byte[] generateWrappedKey(byte[] keyToWrap) throws OperatorException { try { BlockCipher cbcCipher = new CBCBlockCipher(new AESEngine()); IESCipher cipher = new IESCipher( new IESEngine(new ECDHBasicAgreement(), new KDF2BytesGenerator(new SHA1Digest()), new HMac(new SHA1Digest()), new PaddedBufferedBlockCipher(cbcCipher)), 16); // According to the ยง3.8 in SEC 1, Version 2.0: // "Furthermore here the 16 octet or 128 bit IV for AES in CBC mode should always take // the value 0000000000000000_{16}" byte[] iv = new byte[16]; IESParameterSpec spec = new IESParameterSpec(null, null, aesKeySize, aesKeySize, iv); cipher.engineInit(Cipher.ENCRYPT_MODE, publicKey, spec, new SecureRandom()); byte[] bcResult = cipher.engineDoFinal(keyToWrap, 0, keyToWrap.length); // convert the result to ASN.1 format ASN1Encodable[] array = new ASN1Encodable[3]; // ephemeralPublicKey ECPoint byte[] ephemeralPublicKey = new byte[ephemeralPublicKeyLen]; System.arraycopy(bcResult, 0, ephemeralPublicKey, 0, ephemeralPublicKeyLen); array[0] = new DEROctetString(ephemeralPublicKey); // symmetricCiphertext OCTET STRING int symmetricCiphertextLen = bcResult.length - ephemeralPublicKeyLen - macLen; byte[] symmetricCiphertext = new byte[symmetricCiphertextLen]; System.arraycopy(bcResult, ephemeralPublicKeyLen, symmetricCiphertext, 0, symmetricCiphertextLen); array[1] = new DEROctetString(symmetricCiphertext); // macTag OCTET STRING byte[] macTag = new byte[macLen]; System.arraycopy(bcResult, ephemeralPublicKeyLen + symmetricCiphertextLen, macTag, 0, macLen); array[2] = new DEROctetString(macTag); return new DERSequence(array).getEncoded(); } catch (Exception ex) { throw new OperatorException("error while generateWrappedKey", ex); } }
Example #8
Source File: CrmfKeyWrapper.java From xipki with Apache License 2.0 | votes |
abstract byte[] generateWrappedKey(byte[] encryptionKey) throws OperatorException;