I'm trying to crypt and decrypt with Rijndael (Cryptix). The code above work fine with some data and Keys, but with some, the error message appears: cryptix.CryptixException: PKCS#7: Invalid number of padding bytes.
e.g.
----------------
Work fine:
String test = Crypt("BugBill","Beer9");
String test1 = DeCrypt(test,"Beer9");
BugBill
If change 1 byte Don't work:
String test = Crypt("BugBill","Beer2");
String test1 = DeCrypt(test,"Beer2");
cryptix.CryptixException: PKCS#7: Invalid number of padding bytes.
--------------------Crypt---------------------------------------------
import cryptix.provider.key.RawSecretKey;
import xjava.security.*;
public class Cifrador {
Cipher crypT = null;
public String Crypt(String data, String key) {
java.security.Security.addProvider(new cryptix.provider.Cryptix());
byte[] bytesCry = null;
try {
crypT = Cipher.getInstance ("Rijndael/ECB/PKCS#7", "Cryptix");
} catch (java.lang.Exception x)
{ System.out.println ("Exception: "+x); }
int i = key.length(); // If the key is < 16 bytes
for (int a=i; a<16; a++) key=(key+'0'); // fill with "0"
RawSecretKey keyAES = new RawSecretKey("Rijndael", key.getBytes());
try{
crypT.initEncrypt(keyAES);
bytesCry = crypT.crypt(data.getBytes());
} catch (java.lang.Exception x)
{ System.out.println("Exception: "+x); }
String bytesCryS = new String(bytesCry);
return bytesCryS;
}
}
--------------------decrypt---------------------------------------------
import cryptix.provider.key.RawSecretKey;
import xjava.security.*;
public class Decifrador {
Cipher decrypT = null;
public String Decrypt(String data, String key) {
java.security.Security.addProvider(new cryptix.provider.Cryptix());
byte[] bytesDecry = null;
String ERROR = "0";
try {
decrypT = Cipher.getInstance("Rijndael/ECB/PKCS#7", "Cryptix");
} catch (java.lang.Exception x)
{ System.out.println("Exception: "+x); }
int i = chave.length();
for (int a=i; a<16; a++) chave=(chave+'0');
RawSecretKey keyAES = new RawSecretKey("Rijndael", key.getBytes());
try{
decrypT.initDecrypt(keyAES);
// The problem goes here
bytesDecry = decrypT.crypt(data.getBytes());
} catch(java.lang.Exception x)
{System.out.println("Exception: "+x);
return ERRO;
}
String bytesDecryS = new String(bytesDecry);
return bytesDecryS;
}
}
What's wrong??????
Leonel