Encrypting a string

Hi,
I am trying to encrypt a string before writing it to the database and then trying to decrypt it while fetching from the database.
I have a java program using Cipher class to
Cipher pbeCipher = Cipher.getInstance(“PBEWithMD5AndDES”);

This statement works when I try it from a Java Program. But when I create this as a webMethods Java service, I am getting an exception “exceptionjava.security.NoSuchAlgorithmException: Algorithm PBEWithMD5AndDES not implemented.”

Any ideas?
Thanks

I think Cipher is not a standard java package. (javax.crypto) You need to included the corresponding jar in the classpath, and that should work.

Quite unrelated, but the following works on my IS without any changes in classpath.

MessageDigest messagedigest = MessageDigest.getInstance(“MD5”);

Yes, Cipher is part of the JCE spec which is an optional extension for pre 1.4 JDKs.

Are you using the same VM when running the standalone program versus the Integration Server?

The Integration Server includes a JCE provider that has PBE, but the name has different capitialization. Can you try the following instead? PbeWithMD5AndDES_CBC

I know…it really sucks that there aren’t standard names for specifying common cipher capabilities.

MessageDigest works as a one way hashing. But with Cipher I can just encrypt the string and send it and decrypt in the backend back to the actual string.
Thats why I decided to use Cipher class.
And I am using the same VM when I try to run the service from my local machine. The last time I heard from wm support was about the classpath for my developer being the same as the command prompt from where I am running this program. Those are the same too.

Here is the error that I am getting.
PBEKeySpecNoSuchAlgorithmExceptionjava.security.NoSuchAlgorithmException: Algorithm PbeWithMD5AndDES_CBC not implemented.

Has anyone implemented the encrypting a string thing?
Thanks

Are you getting this error when running your standalone program or within the Integration Server?

Consult your JDK documentation for the available PBE cipher names if you’re running in a standalone program (sounds like PBEWithMD5AndDES works for you).

If you’re running a Java service within the context of the Integration Server, you need to use the one I suggested. Here’s a snippet of Java source that doesn’t throw an exception:

try {
Cipher cipher = Cipher.getInstance(“PbeWithMD5AndDES_CBC”);
cipher.getIV();

} catch (Throwable t)
{
t.printStackTrace();
}

Thanks a lot Ed. That worked. Now another error.
InvalidKeyException - java.security.InvalidKeyException: Must be a PBEKey in RAW format.

This is what I get now.
Another question. If I get a string encrypted using this format, How do I input it into another service to get it encrypted?

Thanks in advance!