List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME
String PROVIDER_NAME
To view the source code for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME.
Click Source Link
From source file:no.difi.oxalis.commons.bouncycastle.BCHelperTest.java
License:EUPL
@Test public void simpleRegisterProvider() { if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) != null) Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); Assert.assertNull(Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)); BCHelper.registerProvider();// w w w. ja v a 2 s . co m Provider provider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME); Assert.assertNotNull(provider); BCHelper.registerProvider(); Assert.assertTrue(provider == Security.getProvider(BouncyCastleProvider.PROVIDER_NAME)); }
From source file:no.difi.oxalis.commons.bouncycastle.BCHelperTest.java
License:EUPL
@Test(expectedExceptions = NoSuchAlgorithmException.class) public void triggerExceptionWhenProviderIsNotFound() throws Exception { Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME); BCHelper.getMessageDigest("SHA-512"); }
From source file:no.difi.oxalis.test.util.CertificateValidationTest.java
License:EUPL
public void validateCertificate(X509Certificate certificate) { try {/* w w w. j a v a2 s .c o m*/ List<X509Certificate> certificateList = new ArrayList<X509Certificate>(); certificateList.add(certificate); CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME); CertPath certPath = certificateFactory.generateCertPath(certificateList); KeyStore trustStore = loadKeystore("security/oxalis-dummy-ca.jks", "peppol"); // Create the parameters for the validator PKIXParameters params = new PKIXParameters(trustStore); // Disable revocation checking as we trust our own truststore (and do not have a CRL and don't want OCSP) params.setRevocationEnabled(false); // Validate the certificate path CertPathValidator pathValidator = CertPathValidator.getInstance("PKIX", BouncyCastleProvider.PROVIDER_NAME); CertPathValidatorResult validatorResult = pathValidator.validate(certPath, params); // Get the CA used to validate this path PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) validatorResult; TrustAnchor ta = result.getTrustAnchor(); X509Certificate trustCert = ta.getTrustedCert(); } catch (Exception e) { throw new IllegalStateException("Unable to trust the signer : " + e.getMessage(), e); } }
From source file:no.difi.sdp.client.internal.CreateCMSDocument.java
License:Apache License
public CMSDocument createCMS(byte[] bytes, Sertifikat sertifikat) { try {// ww w .j a v a 2 s. c om JceKeyTransRecipientInfoGenerator recipientInfoGenerator = new JceKeyTransRecipientInfoGenerator( sertifikat.getX509Certificate(), keyEncryptionScheme) .setProvider(BouncyCastleProvider.PROVIDER_NAME); CMSEnvelopedDataGenerator envelopedDataGenerator = new CMSEnvelopedDataGenerator(); envelopedDataGenerator.addRecipientInfoGenerator(recipientInfoGenerator); OutputEncryptor contentEncryptor = new JceCMSContentEncryptorBuilder(cmsEncryptionAlgorithm).build(); CMSEnvelopedData cmsData = envelopedDataGenerator.generate(new CMSProcessableByteArray(bytes), contentEncryptor); return new CMSDocument(cmsData.getEncoded()); } catch (CertificateEncodingException e) { throw new KonfigurasjonException("Feil med mottakers sertifikat", e); } catch (CMSException e) { throw new KonfigurasjonException("Kunne ikke generere Cryptographic Message Syntax for dokumentpakke", e); } catch (IOException e) { throw new RuntimeIOException(e); } }
From source file:no.digipost.api.client.filters.response.ResponseSignatureFilter.java
License:Apache License
public X509Certificate lastSertifikat() { try {/*from ww w .ja v a 2 s. c o m*/ InputStream certStream = new ByteArrayInputStream( apiService.getEntryPoint().getCertificate().getBytes()); CertificateFactory cf = CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME); X509Certificate sertifikat = (X509Certificate) cf.generateCertificate(certStream); if (sertifikat == null) { throw new DigipostClientException(SERVER_SIGNATURE_ERROR, "Kunne ikke laste Digipost's public key - server-signatur kunne ikke sjekkes"); } return sertifikat; } catch (GeneralSecurityException e) { throw new DigipostClientException(SERVER_SIGNATURE_ERROR, "Kunne ikke laste Digiposts public key - server-signatur kunne ikke sjekkes"); } }
From source file:no.digipost.api.client.security.CryptoUtil.java
License:Apache License
public static void verifyJCE() { try {//from w w w . j a v a 2s . c om if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { Security.addProvider(new BouncyCastleProvider()); } new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES256_CBC) .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(); } catch (CMSException e) { throw new RuntimeException( "Feil under initialisering av algoritmer. Er Java Cryptographic Excetsions (JCE) installert?", e); } }
From source file:no.digipost.api.client.util.Encrypter.java
License:Apache License
private Encrypter(DigipostPublicKey key) { this.key = key; this.encryptorBuilder = new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES256_CBC) .setProvider(BouncyCastleProvider.PROVIDER_NAME); }
From source file:no.digipost.api.config.SecurityInitializer.java
License:Apache License
public static void ensureBC() { if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { Security.addProvider(new BouncyCastleProvider()); }/* ww w .j ava 2s . c o m*/ }
From source file:no.digipost.api.interceptors.WsSecurityInterceptor.java
License:Apache License
@Override public void afterPropertiesSet() { Merlin crypto = new Merlin(); crypto.setCryptoProvider(BouncyCastleProvider.PROVIDER_NAME); crypto.setKeyStore(keystoreInfo.keystore); crypto.setTrustStore(keystoreInfo.keystore); interceptor.setSecurementSignatureParts(getSignParts()); interceptor.setSecurementSignatureIfPresentParts("{}cid:Attachments"); interceptor.setSecurementSignatureCrypto(crypto); interceptor.setSecurementSignatureUser(keystoreInfo.alias); interceptor.setSecurementPassword(keystoreInfo.password); interceptor.setValidationSignatureCrypto(crypto); interceptor.setExceptionResolver(exceptionResolver); }
From source file:no.digipost.api.security.OrgnummerExtractorTest.java
License:Apache License
private void sjekkOrgnummer(final String prodVirksomhetssertifikat, final String orgnummer) throws CertificateException, NoSuchProviderException { Security.addProvider(new BouncyCastleProvider()); CertificateFactory cf = CertificateFactory.getInstance("X.509", BouncyCastleProvider.PROVIDER_NAME); X509Certificate certificate = (X509Certificate) cf .generateCertificate(new ByteArrayInputStream(prodVirksomhetssertifikat.getBytes())); OrgnummerExtractor extractor = new OrgnummerExtractor(); Organisasjonsnummer orgNr = extractor.from(certificate); assertEquals(orgnummer, orgNr.toString()); }