Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.thiagoitagaki;
- import sun.misc.BASE64Decoder;
- import javax.crypto.Cipher;
- import java.io.IOException;
- import java.security.GeneralSecurityException;
- import java.security.KeyFactory;
- import java.security.PrivateKey;
- import java.security.spec.PKCS8EncodedKeySpec;
- public class Main {
- public static void main(String[] args) throws IOException, GeneralSecurityException {
- String keyString = "<PUT_YOUR_KEY_VALUE_HERE>";
- PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(new BASE64Decoder().decodeBuffer(keyString)));
- String encryptedData = "<PUT_YOUR_ENCRYPTED_DATA_HERE>";
- String decryptedData = decrypt(privateKey, encryptedData);
- System.out.print("Raw data: " + decryptedData);
- }
- private static String decrypt(PrivateKey key, String data) throws GeneralSecurityException, IOException {
- Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
- cipher.init(Cipher.DECRYPT_MODE, key);
- return new String(cipher.doFinal(new BASE64Decoder().decodeBuffer(data)));
- }
- }
Add Comment
Please, Sign In to add comment