Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Boolean decryptSessionKey() {
- // first, base64 decode the session key
- String sslString = "openssl base64 -d -in enc_sesskey -out temp";
- try {
- Process p = Runtime.getRuntime().exec(sslString);
- } catch (IOException e2) {
- e2.printStackTrace();
- }
- // now we can decrypt it
- try {
- sslString = "openssl rsautl -in temp -inkey privkey.pem -decrypt";
- Process p = Runtime.getRuntime().exec(sslString);
- BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
- try {
- String s;
- while ((s = stdInput.readLine()) != null) {
- decrypted_session_password = s;
- writeToFile(decrypted_sesskey, s);
- }
- return true;
- } catch (Exception e) {
- return false;
- }
- } catch (IOException e1) {
- return false;
- } catch (Exception e) {
- return false;
- }
- }
- public Boolean encryptSessionKey(Cert receiver_cert) {
- String sslString =
- "openssl rsautl base64 -in sesskey -out temp -inkey cert.pem -encrypt -certin";
- // run this openssl encryption. Note that it will not yet be base64 encoded
- try {
- Process p = Runtime.getRuntime().exec(sslString);
- } catch (IOException e2) {
- e2.printStackTrace();
- }
- // now we base64-encode the encrypted file
- sslString = "openssl base64 -in temp -out enc_sesskey";
- try {
- Process p = Runtime.getRuntime().exec(sslString);
- } catch (IOException e1) {return false;
- } catch (Exception e) {return false;
- }
- return true;
- }
- openssl rsautl -encrypt -in sesskey -inkey cert.pem -certin -out temp
- openssl base64 -e -in temp -out enc_sesskey
- openssl base64 -d -in enc_sesskey -out temp
- openssl rsautl -decrypt -in temp -inkey privkey.pem -out sesskey2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement