Guest User

Untitled

a guest
Oct 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package com.thiagoitagaki;
  2.  
  3. import sun.misc.BASE64Decoder;
  4.  
  5. import javax.crypto.Cipher;
  6. import java.io.IOException;
  7. import java.security.GeneralSecurityException;
  8. import java.security.KeyFactory;
  9. import java.security.PrivateKey;
  10. import java.security.spec.PKCS8EncodedKeySpec;
  11.  
  12. public class Main {
  13.  
  14. public static void main(String[] args) throws IOException, GeneralSecurityException {
  15. String keyString = "<PUT_YOUR_KEY_VALUE_HERE>";
  16. PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(keyString)));
  17.  
  18. String encryptedData = "<PUT_YOUR_ENCRYPTED_DATA_HERE>";
  19. String decryptedData = decrypt(privateKey, encryptedData);
  20. System.out.print("Raw data: " + decryptedData);
  21. }
  22.  
  23. private static String decrypt(PrivateKey key, String data) throws GeneralSecurityException, IOException {
  24. Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
  25. cipher.init(Cipher.DECRYPT_MODE, key);
  26. return new String(cipher.doFinal(new BASE64Decoder().decodeBuffer(data)));
  27. }
  28.  
  29. }
Add Comment
Please, Sign In to add comment