微信支付JSPIA支付-支付通知中,对resource解密
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import java.util.Base64;public class AEADDecryption {public static String decrypt(String key, String nonce, String associatedData, String ciphertext) throws Exception {byte[] keyBytes = key.getBytes();byte[] nonceBytes = nonce.getBytes();byte[] associatedDataBytes = associatedData.getBytes();byte[] ciphertextBytes = Base64.getDecoder().decode(ciphertext);Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");Key secretKey = new SecretKeySpec(keyBytes, "AES");GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(128, nonceBytes);cipher.init(Cipher.DECRYPT_MODE, secretKey, gcmParameterSpec);cipher.updateAAD(associatedDataBytes);byte[] decryptedBytes = cipher.doFinal(ciphertextBytes);return new String(decryptedBytes);}public static void main(String[] args) throws Exception {String key = "v3密钥";String nonce = "iKtWOA7GL44Z";String associatedData = "transaction";String ciphertext = "CTef/rBxYzeKtxpZrGMjGrCGGNumi9iwd47utMPa6d9w3N6Af9mKNcfI8+1s3GZJgnCN0XaBDzIN2D63gYbfByG1eOEyMZF6oK75wj5QRq73lXotTANPxJVYhGxl+ldJjYlrpYuWSSS9pgSaNLRZMzxmK6WMCipt3eZFmVGyHhTKyLSAYdMuxlXngfqF4mMegf0z9sTEMv/vjBNychKVHJAWceqpMvpqbVXzbIa4n601EkFhhl1wXkx7+8rNRzkiHjutXWKQvBFzRe13GTSfVBpFZVcaWHhqcyNxcRtrMi3TQll5lKi2g3YIQ1yO2DTmlfPuzTG6ebYAFn6lP/tJ/KEwl+JYx77Ql8xhkQ9YIXz33Sbd4TCgw2gv2SgpfNrg3X3L6Kldo7iPrJ6OqE2nrdsNX9gjwMbDWhAWopedXEI/dccrZy9h/f25fpqGEdqVzbX5w0Yg4DtG1WnyXascFXgDzAGXYzuiJFl4egtsl5Qirh5wyUJUoDe7zKJDXocgmTSIkFn9jeuEitlaECqzElS44j8wOXcn3uizOvjfihFAQAqTANT0oFFHk=";String plaintext = decrypt(key, nonce, associatedData, ciphertext);System.out.println("Decrypted plaintext: " + plaintext);}
}