Support for the following algorithms by the SunJCE provider:
DES
DESede
Blowfish
PBEWithMD5AndDES
PBEWithMD5AndTripleDES
Diffie-Hellman key agreement among multiple parties
HmacMD5
HmacSHA1
DES
DESede
Blowfish
PBEWithMD5AndDES
PBEWithMD5AndTripleDES
Diffie-Hellman key agreement among multiple parties
HmacMD5
HmacSHA1
Support for the following algorithms by the SunJCE provider:
DES
DESede
Blowfish
PBEWithMD5AndDES
PBEWithMD5AndTripleDES
Diffie-Hellman key agreement among multiple parties
HmacMD5
HmacSHA1
Cipher.doFinal(cleartext);
我的原代码:import xjava.security.Cipher;
import cryptix.provider.mode.*;
import xjava.security.KeyGenerator;
import java.security.*;
import xjava.security.Mode;
import xjava.security.*;
public class Test {
private static PublicKey pubkey;
private static PrivateKey prikey;
public static void main(String[] args)
{
byte[] data = new byte[30];
for(int i = 0; i < 30; i++)
data[i] = (byte)i;
if(!createSecurtyKeys())
return;
byte[] edata = enCode(data,pubkey);
if(edata ==null) return;
byte[] ddata = deCode(edata,prikey);
if(ddata == null) return;
for(int i = 0;i < ddata.length; i++)
System.out.print(ddata[i]+"\t");
} public static boolean createSecurtyKeys()
{
try
{
SecureRandom secrand=new SecureRandom();
java.security.KeyPairGenerator keygen=java.security.KeyPairGenerator.getInstance("RSA","Cryptix");
keygen.initialize(512,secrand); //初始化密钥生成器 KeyPair keys=keygen.generateKeyPair(); //生成密钥组
pubkey = keys.getPublic();
prikey = keys.getPrivate();
/*把公共密钥和私有密钥分别保存于相应的文件中*/
return true;
}
catch(Exception e)
{
System.out.println();
return false;
}
} public static byte[] enCode(byte[] data,Key key)
{
Cipher cipher = null;
try
{
cipher = Cipher.getInstance("RSA");
cipher.initEncrypt(key);
cipher.update(data);
return cipher.doFinal(data);/**此处出错
}
catch(Exception e)
{
System.out.println(e);
return null;
}
} public static byte[] deCode(byte[] data,Key key)
{
Cipher cipher = null;
try
{
cipher = Cipher.getInstance("RSA");
cipher.initDecrypt(key);
cipher.update(data);
return cipher.doFinal(data);
}
catch(Exception e)
{
System.out.println("Decode Failure!");
return null;
}
}
}