当前位置: 技术问答>java相关
请问谁对用blowfish来做JAVA的加密解密比较熟悉,请帮忙写个文本的加密解密类,(我这有一个但是写得不很成熟不能解密)
来源: 互联网 发布时间:2015-05-11
本文导语: 请问谁对用blowfish来做JAVA的加密解密比较熟悉,请帮忙写个文本的加密解密类,(我这有一个但是写得不很成熟不能解密) 这是源代码。 import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; import javax.crypto.interfac...
请问谁对用blowfish来做JAVA的加密解密比较熟悉,请帮忙写个文本的加密解密类,(我这有一个但是写得不很成熟不能解密)
这是源代码。
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
import com.sun.crypto.provider.SunJCE;
public class SuperCode {
private KeyGenerator keygen;
private SecretKey skey ;
private Cipher cipher;
private byte[] code=new byte[1024*8];
SecretKeySpec skeySpec;
byte[] raw;
//constructor
public SuperCode( ) {
try{
//if(keygen==null){
keygen = KeyGenerator.getInstance("Blowfish");
// }
// if(skey==null) {
skey = keygen.generateKey();
// }
// if(cipher==null){
cipher = Cipher.getInstance("Blowfish");
// }
}catch(Exception unreported){
keygen=null;
skey=null;
cipher=null;
System.out.println("初始化错误");
}
}
public String encrypt(String encryptCode){
try{
String temp;
raw = skey.getEncoded();
skeySpec = new SecretKeySpec(raw, "Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
code=cipher.doFinal(encryptCode.getBytes());
encryptCode=( new Byte(code[1])).toString();
for (int i=1; i
这是源代码。
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
import com.sun.crypto.provider.SunJCE;
public class SuperCode {
private KeyGenerator keygen;
private SecretKey skey ;
private Cipher cipher;
private byte[] code=new byte[1024*8];
SecretKeySpec skeySpec;
byte[] raw;
//constructor
public SuperCode( ) {
try{
//if(keygen==null){
keygen = KeyGenerator.getInstance("Blowfish");
// }
// if(skey==null) {
skey = keygen.generateKey();
// }
// if(cipher==null){
cipher = Cipher.getInstance("Blowfish");
// }
}catch(Exception unreported){
keygen=null;
skey=null;
cipher=null;
System.out.println("初始化错误");
}
}
public String encrypt(String encryptCode){
try{
String temp;
raw = skey.getEncoded();
skeySpec = new SecretKeySpec(raw, "Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
code=cipher.doFinal(encryptCode.getBytes());
encryptCode=( new Byte(code[1])).toString();
for (int i=1; i