Search in sources :

Example 21 with BouncyCastleProvider

use of org.bouncycastle.jce.provider.BouncyCastleProvider in project RPlay by bencall.

the class RTSPResponder method decryptRSA.

/**
	 * Decrypt with RSA priv key
	 * @param array
	 * @return
	 */
public byte[] decryptRSA(byte[] array) {
    try {
        Security.addProvider(new BouncyCastleProvider());
        // La clef RSA
        PEMReader pemReader = new PEMReader(new StringReader(key));
        KeyPair pObj = (KeyPair) pemReader.readObject();
        // Encrypt
        Cipher cipher = Cipher.getInstance("RSA/NONE/OAEPPadding");
        cipher.init(Cipher.DECRYPT_MODE, pObj.getPrivate());
        return cipher.doFinal(array);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : KeyPair(java.security.KeyPair) PEMReader(org.bouncycastle.openssl.PEMReader) StringReader(java.io.StringReader) Cipher(javax.crypto.Cipher) IOException(java.io.IOException) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 22 with BouncyCastleProvider

use of org.bouncycastle.jce.provider.BouncyCastleProvider in project RPlay by bencall.

the class RTSPResponder method encryptRSA.

/**
	 * Crypts with private key
	 * @param array	data to encrypt
	 * @return encrypted data
	 */
public byte[] encryptRSA(byte[] array) {
    try {
        Security.addProvider(new BouncyCastleProvider());
        PEMReader pemReader = new PEMReader(new StringReader(key));
        KeyPair pObj = (KeyPair) pemReader.readObject();
        // Encrypt
        Cipher cipher = Cipher.getInstance("RSA/NONE/PKCS1Padding");
        cipher.init(Cipher.ENCRYPT_MODE, pObj.getPrivate());
        return cipher.doFinal(array);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : KeyPair(java.security.KeyPair) PEMReader(org.bouncycastle.openssl.PEMReader) StringReader(java.io.StringReader) Cipher(javax.crypto.Cipher) IOException(java.io.IOException) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 23 with BouncyCastleProvider

use of org.bouncycastle.jce.provider.BouncyCastleProvider in project Openfire by igniterealtime.

the class AesEncryptor method initialize.

/** Installs the required security provider(s) */
private synchronized void initialize() {
    if (!isInitialized) {
        try {
            Security.addProvider(new BouncyCastleProvider());
            isInitialized = true;
        } catch (Throwable t) {
            log.warn("JCE provider failure; unable to load BC", t);
        }
    }
}
Also used : BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 24 with BouncyCastleProvider

use of org.bouncycastle.jce.provider.BouncyCastleProvider in project OpenAttestation by OpenAttestation.

the class X509Util method decodeDerCertificate.

/**
     * Reads a DER-encoded certificate and creates a corresponding X509Certificate
     * object.
     * @param certificateBytes
     * @return
     * @throws CertificateException 
     */
public static X509Certificate decodeDerCertificate(byte[] certificateBytes) throws CertificateException {
    //        CertificateFactory cf = CertificateFactory.getInstance("X.509");
    java.security.cert.CertificateFactory cf = java.security.cert.CertificateFactory.getInstance("X.509", new BouncyCastleProvider());
    X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certificateBytes));
    return cert;
}
Also used : CertificateFactory(java.security.cert.CertificateFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) X509Certificate(java.security.cert.X509Certificate) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 25 with BouncyCastleProvider

use of org.bouncycastle.jce.provider.BouncyCastleProvider in project OpenAttestation by OpenAttestation.

the class HisPrivacyCAWebService2ImplTest method testRequestGetEC.

@Test
public void testRequestGetEC() throws Exception {
    Security.addProvider(new BouncyCastleProvider());
    X509Certificate pcaCert = TpmUtils.certFromP12(homeFolder + PrivacyCaFileName, PrivacyCaPassword);
    String EkMod = "12ef45";
    SecretKey deskey = generateSessionKey();
    byte[] encryptedEkMod = TpmUtils.encryptDES(TpmUtils.hexStringToByteArray(EkMod), deskey);
    byte[] encryptedSessionKey = TpmUtils.encryptRSA(deskey.getEncoded(), (RSAPublicKey) pcaCert.getPublicKey());
    byte[] encryptEkCert = hisPrivacyCAWebService2Impl.requestGetEC(encryptedEkMod, encryptedSessionKey, ValidityDays);
    assertNotNull(encryptEkCert);
}
Also used : SecretKey(javax.crypto.SecretKey) X509Certificate(java.security.cert.X509Certificate) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Test(org.junit.Test)

Aggregations

BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)34 IOException (java.io.IOException)12 KeyPair (java.security.KeyPair)9 X509Certificate (java.security.cert.X509Certificate)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 KeyPairGenerator (java.security.KeyPairGenerator)6 KeyStore (java.security.KeyStore)6 SecureRandom (java.security.SecureRandom)5 Date (java.util.Date)5 JcaX509CertificateConverter (org.bouncycastle.cert.jcajce.JcaX509CertificateConverter)5 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 SecretKey (javax.crypto.SecretKey)4 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)4 Before (org.junit.Before)4 KeyStoreException (java.security.KeyStoreException)3 NoSuchProviderException (java.security.NoSuchProviderException)3 CertificateException (java.security.cert.CertificateException)3 X500Name (org.bouncycastle.asn1.x500.X500Name)3 Test (org.junit.Test)3