mhhh... le funzioni son le stesse più o meno
codice:
/**
* Decrypt BASE64 encoded text using private key
* @param text The encrypted text, encoded as BASE64
* @param key The private key
* @return The unencrypted text encoded as UTF8
* @throws java.lang.Exception
*/
public String decrypt(String text, Key key) throws Exception{
String result;
try{
// decrypt the text using the private key
byte[] dectyptedText = decrypt(decodeBASE64(text),key);
result = new String(dectyptedText, "UTF8");
System.out.println("Decrypted text is: " + result);
}catch (Exception e){
e.printStackTrace();
throw e;
}
return result;
}
public byte[] decrypt(byte[] text, Key key) throws Exception{
byte[] dectyptedText = null;
try{
// decrypt the text using the private key
Cipher cipher = Cipher.getInstance(ALGORITHM + "/" + MODE + "/" + PADDING);
System.out.println("Start decryption");
cipher.init(Cipher.DECRYPT_MODE, key);
dectyptedText = cipher.doFinal(text);
}catch (Exception e){
e.printStackTrace();
throw e;
}
return dectyptedText;
}