Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static byte [] encrypt(String plaintext) throws Exception {
- KeyStore keyStore = getKeyStore();
- Certificate[] certs = keyStore.getCertificateChain("alias");
- Cipher cipher = Cipher.getInstance("RSA","BC");
- cipher.init(Cipher.ENCRYPT_MODE, certs[0].getPublicKey());
- return cipher.doFinal(plaintext.getBytes());
- }
- KeyStore keyStore = getKeyStore();
- PrivateKey privateKey = (PrivateKey) keyStore.getKey("alias",
- "password".toCharArray());
- Cipher cipher = Cipher.getInstance("RSA","BC");
- cipher.init(Cipher.DECRYPT_MODE, privateKey);
- byte[] cipherbyte=cipher.doFinal(ciphertext);
- return new String(cipherbyte);
- }
- Caused by: javax.crypto.BadPaddingException: Given final block not properly padded
- at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:966)
- at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824)
- at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436)
- at javax.crypto.Cipher.doFinal(Cipher.java:2165)
- at
Add Comment
Please, Sign In to add comment