daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private static byte [] encrypt(String plaintext) throws Exception {
  2.  
  3.         KeyStore keyStore = getKeyStore();
  4.         Certificate[] certs = keyStore.getCertificateChain("alias");
  5.         Cipher cipher = Cipher.getInstance("RSA","BC");
  6.         cipher.init(Cipher.ENCRYPT_MODE, certs[0].getPublicKey());
  7.         return cipher.doFinal(plaintext.getBytes());
  8.     }
  9.    
  10. KeyStore keyStore = getKeyStore();
  11.     PrivateKey privateKey = (PrivateKey) keyStore.getKey("alias",
  12.             "password".toCharArray());
  13.     Cipher cipher = Cipher.getInstance("RSA","BC");
  14.     cipher.init(Cipher.DECRYPT_MODE, privateKey);
  15.     byte[] cipherbyte=cipher.doFinal(ciphertext);
  16.     return new String(cipherbyte);
  17. }
  18.    
  19. Caused by: javax.crypto.BadPaddingException: Given final block not properly padded
  20.     at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:966)
  21.     at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824)
  22.     at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436)
  23.     at javax.crypto.Cipher.doFinal(Cipher.java:2165)
  24.     at
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top