关于cryptix JCE的配置使用
我根据网上的文章,下载了cryptix-jce-20050328-snap.zip并且解压和把里面的jar包放在了jdk的相应目录下,也设置了它们的CLASSPATH,同时设置了java.security文件,片段如下:
...
security.provider.1=sun.security.provider.Sun
security.provider.2=com.sun.net.ssl.internal.ssl.Provider
security.provider.3=com.sun.rsajca.Provider
security.provider.4=com.sun.crypto.provider.SunJCE
security.provider.5=sun.security.jgss.SunProvider
security.provider.6=cryptix.jce.provider.cipher.TripleDES
...
网上的例子是这样的:
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class Simple3DES
{
public static void main(String[] args)
{
try
{
String sKey = "123456789012345678901234";
SecretKeySpec skeySpec = new SecretKeySpec(sKey.getBytes(),
"TripleDES");
Cipher cipher = Cipher.getInstance("TripleDES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] cleartext = "testcontent".getBytes();
byte[] encrypted = cipher.doFinal(cleartext, 0, cleartext.length);
StringBuffer sb = new StringBuffer();
for ( int j = 0; j < encrypted.length; j++ )
{
int k = encrypted[j];
if ( k < 0 )
k += 256;
sb.append("%" + Integer.toHexString(k).toUpperCase());
}
System.err.println("result:" + sb.toString());
}
catch ( Exception e )
{
System.err.println("Caught exception " + e.toString());
}
}
}
但是,当我运行的时候,总是说:Caught exception java.security.NoSuchAlgorithmException: Cannot find any provider supporting TripleDES。
请问,我还要怎么配置呢?或者我应该怎样结合jdk使用cryptix JCE呢?因为我是新手,谢谢大家指点!