Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package expressCheckout;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.crypto.Cipher;
- import javax.crypto.spec.IvParameterSpec;
- import javax.crypto.spec.SecretKeySpec;
- import org.json.JSONException;
- import org.json.JSONObject;
- /**
- * DecryptParameters decryption class
- *
- * @author Mula
- */
- public class DecryptParameters {
- /**
- * Define the your IV and Secret Key.
- */
- static String IV = "******";
- static String encryptionKey = "*******";
- /**
- * Main function.
- *
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- try {
- // Get the encrypted string from the payload during the callback.
- String encryptedString = "**********************";
- // Instead consume the parameter object as you may wish.
- System.out.println(decrypt(hexToBytes(encryptedString), encryptionKey));
- } catch (JSONException ex) {
- Logger.getLogger(DecryptParameters.class.getName()).log(Level.SEVERE, null, ex);
- } catch (Exception ex) {
- Logger.getLogger(DecryptParameters.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * Convert string to byte
- *
- * @param string String
- *
- * @return data byte[]
- */
- public static byte[] hexToBytes(String string) {
- if (string == null) {
- return null;
- } else if (string.length() < 2) {
- return null;
- } else {
- int len = string.length() / 2;
- byte[] buffer = new byte[len];
- for (int i = 0; i < len; i++) {
- buffer[i] = (byte) Integer.parseInt(string.substring(i * 2, i * 2 + 2), 16);
- }
- return buffer;
- }
- }
- /**
- * Decrypt the encrypted bytes to string
- *
- * @param cipherText byte[]
- * @param encryptionKey String
- *
- * @return string String
- * @throws java.lang.Exception
- */
- public static String decrypt(byte[] cipherText, String encryptionKey) throws Exception {
- Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
- SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
- cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(IV.getBytes("UTF-8")));
- return new String(cipher.doFinal(cipherText), "UTF-8");
- }
- }
Add Comment
Please, Sign In to add comment