Example usage for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME

List of usage examples for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME

Introduction

In this page you can find the example usage for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME.

Prototype

String PROVIDER_NAME

To view the source code for org.bouncycastle.jce.provider BouncyCastleProvider PROVIDER_NAME.

Click Source Link

Usage

From source file:ch.uzh.fabric.config.SampleStore.java

License:Open Source License

static PrivateKey getPrivateKeyFromBytes(byte[] data)
        throws IOException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {

    final PEMParser pemParser = new PEMParser(new StringReader(new String(data)));

    PrivateKeyInfo pemPair = (PrivateKeyInfo) pemParser.readObject();

    PrivateKey privateKey = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME)
            .getPrivateKey(pemPair);//  w w w.  jav  a  2  s .  c om

    return privateKey;
}

From source file:cn.com.rexen.ext.shiro.authc.x509.X509AuthenticationToken.java

License:Open Source License

public X509Store getX509CertChainStore() {
    try {// w w w.j  a v a 2s.  c om
        X509CollectionStoreParameters params = new X509CollectionStoreParameters(Arrays.asList(certChain));
        return X509Store.getInstance("CERTIFICATE/COLLECTION", params, BouncyCastleProvider.PROVIDER_NAME);
    } catch (NoSuchStoreException ex) {
        return null;
    } catch (NoSuchProviderException ex) {
        return null;
    }
}

From source file:cn.com.rexen.ext.shiro.authc.x509.X509CredentialsPKIXPathMatcher.java

License:Open Source License

@Override
public boolean doX509CredentialsMatch(X509AuthenticationToken token, X509AuthenticationInfo info) {
    try {//w  ww  .  ja va 2s  .c  o m

        ExtendedPKIXBuilderParameters params = new ExtendedPKIXBuilderParameters(info.getGrantedTrustAnchors(),
                token.getX509CertSelector());
        params.addStore(token.getX509CertChainStore());
        params.setRevocationEnabled(false);

        CertPathBuilder pathBuilder = CertPathBuilder.getInstance("PKIX", BouncyCastleProvider.PROVIDER_NAME);
        CertPathBuilderResult result = pathBuilder.build(params);

        if (LOGGER.isDebugEnabled()) {
            PKIXCertPathReviewer reviewer = new PKIXCertPathReviewer(result.getCertPath(), params);
            String certPathEnd = ((X509Certificate) reviewer.getCertPath().getCertificates()
                    .get(reviewer.getCertPathSize() - 1)).getSubjectX500Principal().getName();
            LOGGER.debug(
                    "A valid ({}) certification path (length: {}) was found for the following certificate: '{}' ending on: '{}'",
                    new Object[] { reviewer.isValidCertPath(), reviewer.getCertPathSize(),
                            token.getX509Certificate().getSubjectX500Principal().getName(), certPathEnd });
        }

        return true;

    } catch (GeneralSecurityException ex) {
        LOGGER.trace("Unable to do credentials matching", ex);
        return false;
    } catch (CertPathReviewerException ex) {
        LOGGER.trace("Unable to do credentials matching", ex);
        return false;
    }

}

From source file:com.adaptris.security.certificate.X509Handler.java

License:Apache License

private X509Certificate parseCertificate(InputStream input) throws CertificateException, IOException {
    try {//from   ww  w .j  a  v a2s . co m
        CertificateFactory certFactory = CertificateFactory.getInstance("X.509",
                BouncyCastleProvider.PROVIDER_NAME);
        X509Certificate cert = (X509Certificate) certFactory.generateCertificate(input);
        logR.trace("Handling [{}] SerialNumber: {}", cert.getSubjectDN().toString(), cert.getSerialNumber());
        return cert;
        // X509CertParser x509parser = new X509CertParser();
        // x509parser.engineInit(input);
        // return (X509CertificateObject)x509parser.engineRead();
    } catch (NoSuchProviderException e) {
        throw new IOException("Could not parse certificate!", e);
    }
}

From source file:com.aqnote.shared.encrypt.ProviderUtil.java

License:Open Source License

public static void addBCProvider() {
    Provider bcProvider = Security.getProvider(BouncyCastleProvider.PROVIDER_NAME);
    if (bcProvider == null) {
        Security.addProvider(new BouncyCastleProvider());
    }//from   ww  w  . j  av  a2  s . c om
}

From source file:com.axelor.apps.account.ebics.client.EbicsUtils.java

License:Open Source License

/**
 * Encrypts or decrypts the given input according to key spec.
 * @param mode the encryption-decryption mode.
 * @param input the input to encrypt or decrypt.
 * @param keySpec the key spec.//from w w  w.  j a  v a 2s . c  o m
 * @return the encrypted or decrypted data.
 * @throws GeneralSecurityException
 */
private static byte[] encryptOrDecrypt(int mode, byte[] input, SecretKeySpec keySpec) throws AxelorException {
    IvParameterSpec iv;
    Cipher cipher;

    iv = new IvParameterSpec(new byte[16]);
    try {
        cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", BouncyCastleProvider.PROVIDER_NAME);
        cipher.init(mode, keySpec, iv);
        return cipher.doFinal(input);
    } catch (GeneralSecurityException e) {
        throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR);
    }
}

From source file:com.axelor.apps.account.ebics.utils.Utils.java

License:Open Source License

/**
 * Encrypts or decrypts the given input according to key spec.
 * @param mode the encryption-decryption mode.
 * @param input the input to encrypt or decrypt.
 * @param keySpec the key spec.// w ww . jav  a  2s. c  om
 * @return the encrypted or decrypted data.
 * @throws GeneralSecurityException
 */
private static byte[] encryptOrDecrypt(int mode, byte[] input, SecretKeySpec keySpec) throws AxelorException {
    IvParameterSpec iv;
    Cipher cipher;

    iv = new IvParameterSpec(new byte[16]);
    try {
        cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", BouncyCastleProvider.PROVIDER_NAME);
        cipher.init(mode, keySpec, iv);
        return cipher.doFinal(input);
    } catch (GeneralSecurityException e) {
        throw new AxelorException(e.getMessage(), IException.TECHNICAL);
    }
}

From source file:com.axelor.apps.account.ebics.xml.InitializationRequestElement.java

License:Open Source License

/**
 * Generates the upload transaction key//  w ww. j av a 2 s .c o  m
 * @return the transaction key
 */
protected byte[] generateTransactionKey() throws AxelorException {
    try {
        Cipher cipher;

        cipher = Cipher.getInstance("RSA/NONE/PKCS1Padding", BouncyCastleProvider.PROVIDER_NAME);
        cipher.init(Cipher.ENCRYPT_MODE, session.getBankE002Key());

        return cipher.doFinal(nonce);
    } catch (Exception e) {
        e.printStackTrace();
        throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR);
    }
}

From source file:com.billing.ng.crypto.profile.cipher.PublicKeyProfile.java

License:Open Source License

public KeyPair generateKey() {
    KeyPairGenerator keyGen;//from  w  ww . j a v a  2 s  .  c  o m
    try {
        keyGen = KeyPairGenerator.getInstance(identifier, BouncyCastleProvider.PROVIDER_NAME);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Key generator algorithm not supported by the JCE provider.");
    } catch (NoSuchProviderException e) {
        throw new RuntimeException("BouncyCastle JCE provider not configured or not loaded.");
    }

    if (keysize != null)
        keyGen.initialize(keysize);

    return new KeyPair(keyGen.generateKeyPair());
}

From source file:com.cloud.utils.crypt.RSAHelper.java

License:Apache License

private static RSAPublicKey readKey(String key) throws Exception {
    byte[] encKey = Base64.decodeBase64(key.split(" ")[1]);
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(encKey));

    byte[] header = readElement(dis);
    String pubKeyFormat = new String(header);
    if (!pubKeyFormat.equals("ssh-rsa"))
        throw new RuntimeException("Unsupported format");

    byte[] publicExponent = readElement(dis);
    byte[] modulus = readElement(dis);

    KeySpec spec = new RSAPublicKeySpec(new BigInteger(modulus), new BigInteger(publicExponent));
    KeyFactory keyFactory = KeyFactory.getInstance("RSA", BouncyCastleProvider.PROVIDER_NAME);
    RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(spec);

    return pubKey;
}