We just upgraded to JRE 1.3.1 and now the code I was using to do
encryption/decryption using JSS is no longer working.  I thought it was the
version of JSS we were using (it is pretty old), but I upgraded to the
latest version and am seeing the same problem.  Here's the error and the
code snippet:

com.netscape.jss.crypto.BadPaddingException: Padding octet (43) is larger
than block size (8)

System.out.println("encrypting");
String encrypted = encryptString(str);
System.out.println(encrypted);
System.out.println("decrypting");
String decrypted = decryptString(encrypted);
System.out.println(decrypted);

public static String encryptString(String str)
{
    try
    {
        Cipher cipher = ct.getCipherContext(encAlg);
        cipher.initEncrypt(sk, params);
        byte[] plaintext = Cipher.pad(str.getBytes(),
encAlg.getBlockSize());
        byte[] encrypted = cipher.doFinal(plaintext);

        return new String(encrypted);
    }
    catch (Exception e)
    {
        System.out.println(e);
    }

    return null;
}

public static String decryptString(String str)
{
    try
    {
        Cipher cipher = ct.getCipherContext(encAlg);
        cipher.initDecrypt(sk, params);
        byte[] decrypted = cipher.doFinal(str.getBytes());
        byte[] recovered = Cipher.unPad(decrypted, encAlg.getBlockSize());

        return new String(recovered);
    }
    catch (Exception e)
    {
        System.out.println(e);
    }

    return null;
}

Any ideas?

doug davies
[EMAIL PROTECTED]



Reply via email to