Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.security.NoSuchAlgorithmException: Cannot find any provider ...

843811Mar 30 2005 — edited Mar 30 2005
I have implemented a wrapper class for encrypting and decrypting passwords. I have compiled and successfully tested this class on a Win32 environment with no problem. Once deployed on a debian/GNU linux installation attempting to run the same code results in the following exception being thrown. Both systems are running the same version of Sun Java (which is 1.4)

java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/ECB/PKCS5Padding

Here is a (truncated) copy of the code I've developed...
public class CryptCodec
{
    private static CryptCodec ourInstance = null;
    private static final Log log = LogFactory.getLog(CryptCodec.class);

    private String algorithm;
    private String mode;
    private String padding;
    private byte[] secretKey;

    .
    .
    .

    private CryptCodec()
    {
        Provider sunJce = new com.sun.crypto.provider.SunJCE();
        Security.addProvider(sunJce);

        .
        .
        .
    }

    private String getTransformation()
    {
        //returns AES/ECB/PKCS5Padding
        return algorithm + "/" + mode + "/" + padding;
    }

    public String encrypt(String plain) throws CryptCodecException
    {
        log.debug("Encrypting plain string '" + plain + "'using key: '" + new String(Base64.encode(secretKey)) + "'");

        byte[] bytes = new byte[0];
        try
        {
            Cipher cipher = Cipher.getInstance(getTransformation());
            SecretKeySpec sKeySpec = new SecretKeySpec(secretKey, algorithm);

            cipher.init(Cipher.ENCRYPT_MODE, sKeySpec);
            bytes = cipher.doFinal(plain.getBytes());
        }
        catch (GeneralSecurityException e)
        {
            throw new CryptCodecException("An exception was thrown whilst trying to encrypt", e);
        }

        return new String(Base64.encode(bytes));
    }

    public String decrypt(String crypt) throws CryptCodecException
    {
        log.debug("Decrypting plain string '" + crypt + "'using key: '" + new String(Base64.encode(secretKey)) + "'");

        byte[] bytes = new byte[0];
        try
        {
            Cipher cipher = Cipher.getInstance(getTransformation());
            SecretKeySpec sKeySpec = new SecretKeySpec(secretKey, algorithm);

            cipher.init(Cipher.DECRYPT_MODE, sKeySpec);

            byte[] decoded = Base64.decode(crypt.getBytes());
            bytes = cipher.doFinal(decoded);
        }
        catch (GeneralSecurityException e)
        {
            throw new CryptCodecException("An exception was thrown whilst trying to decrypt", e);
        }

        return new String(bytes);
    }
}
Does anyone have any ideas? I'd really appreciate it if someone could point me toward a possible cause for this problem.

Cheers
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 27 2005
Added on Mar 30 2005
3 comments
886 views