use of org.bouncycastle.openssl.PEMReader in project MSEC by Tencent.
the class Tools method loadPrivKeyFromFile.
public static PrivateKey loadPrivKeyFromFile(String filename) {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
try {
FileReader fr = new FileReader(filename);
PEMReader pr = new PEMReader(fr);
KeyPair key = (KeyPair) (pr.readObject());
pr.close();
fr.close();
return key.getPrivate();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of org.bouncycastle.openssl.PEMReader in project nhin-d by DirectProject.
the class CAPanel method signCSR.
private void signCSR() {
JFileChooser fc = new JFileChooser();
fc.setDragEnabled(false);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setDialogTitle("Open Signing Request PEM File");
int result = fc.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
final File fl = fc.getSelectedFile();
PEMReader reader = null;
try {
reader = new PEMReader(new InputStreamReader(FileUtils.openInputStream(fl)));
final PKCS10CertificationRequest certReq = (PKCS10CertificationRequest) reader.readObject();
certReq.verify();
final X509Certificate signedCert = CertGenerator.createCertFromCSR(certReq, currentCert);
// validate the certificate
signedCert.verify(currentCert.getSignerCert().getPublicKey());
// write it to a file
final String addressName = CryptoExtensions.getSubjectAddress(signedCert);
final File outFile = new File(addressName + ".der");
FileUtils.writeByteArrayToFile(outFile, signedCert.getEncoded());
JOptionPane.showMessageDialog(this, "Signing successful.\r\nCertificate saved to " + outFile.getAbsolutePath(), "CSR Sign", JOptionPane.PLAIN_MESSAGE);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error signging CSR: " + e.getMessage(), "CSR Sign Error", JOptionPane.ERROR_MESSAGE);
} finally {
IOUtils.closeQuietly(reader);
}
}
}
use of org.bouncycastle.openssl.PEMReader 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.openssl.PEMReader 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.openssl.PEMReader in project MSEC by Tencent.
the class Tools method loadPubKeyFromFile.
public static PublicKey loadPubKeyFromFile(String filename) {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
try {
FileReader fr = new FileReader(filename);
PEMReader pr = new PEMReader(fr);
PublicKey key = (PublicKey) (pr.readObject());
pr.close();
fr.close();
return key;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations