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;
}
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;
}
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);
}
}
}
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;
}
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);
}
Aggregations