Post

Replies

Boosts

Views

Activity

How to decrypt RSA version of Apple Pay PaymentToken in java
is there any avaiable demo for java? Acutally, i use code below to decrypt wrappedKey : Cipher oaepFromInit = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding", new org.bouncycastle.jce.provider.BouncyCastleProvider()); OAEPParameterSpec oaepParams = new OAEPParameterSpec("SHA-256", "MGF1", new MGF1ParameterSpec("SHA-1"), PSource.PSpecified.DEFAULT); PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(privKey); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); Key privateKey = keyFactory.generatePrivate(pkcs8KeySpec); oaepFromInit.init(Cipher.DECRYPT_MODE, privateKey, oaepParams); return oaepFromInit.doFinal(wrappedKeyBytes); But this code can't decrypt wrappedKey, always occur error: Exception in thread "main" org.bouncycastle.jcajce.provider.util.BadBlockException: unable to decrypt block at org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi.getOutput(Unknown Source) at org.bouncycastle.jcajce.provider.asymmetric.rsa.CipherSpi.engineDoFinal(Unknown Source) at javax.crypto.Cipher.doFinal(Cipher.java:2168) at Caused by: org.bouncycastle.crypto.InvalidCipherTextException: data wrong at org.bouncycastle.crypto.encodings.OAEPEncoding.decodeBlock(Unknown Source) at org.bouncycastle.crypto.encodings.OAEPEncoding.processBlock(Unknown Source) ... 5 more publicKeyHash value match my publicKey and privateKey, and I can use my publicKey and privatekey to encrypt and decrypt my own text in same algorithm.
0
0
397
Jul ’24