package test;//import com.borland.datastore.*;
//import com.borland.*;
import javax.crypto.*;
import javax.crypto.NoSuchPaddingException;
import java.security.Security;
import java.security.NoSuchAlgorithmException;public class Encrypt {
String encrypt_type="DES";//DES/ECB/PKCS5Padding
KeyGenerator kg = null;
SecretKey key = null;
public Encrypt() {
Security.addProvider( //jce注册
new com.sun.crypto.provider.SunJCE());
}
public static void main(String[] args) { Encrypt et = new Encrypt();
et.initEncrtpt() ;
byte[] data="1o1o99".getBytes() ;
byte[] result=null;
byte[] original =null;
result=et.encrypt(data) ;
original=et.unencrypt(result) ;
System.out.println(data.length);
System.out.println(result.length);
System.out.println(original.length);
} public void setEncrypt_type(String type){
this.encrypt_type =type;
} public void initEncrtpt(){
try{
kg = KeyGenerator.getInstance(encrypt_type);
key = kg.generateKey();
}catch(Exception e){
System.out.println(e.toString());
}
} public byte[] encrypt(byte[] data){
byte[] result=null;
try{
Cipher cipher = Cipher.getInstance(encrypt_type);
cipher.init(Cipher.ENCRYPT_MODE, key);
result=cipher.doFinal(data);
}catch(Exception e){
System.out.println(e.toString()) ;
}
return result;
} public byte[] unencrypt(byte[] result){
byte[] original=null;
try{ Cipher cipher = Cipher.getInstance(encrypt_type);
cipher.init(Cipher.DECRYPT_MODE, key);
original = cipher.doFinal(result);
}catch(Exception e){
System.out.println(e.toString()) ;
}
return original;
}
}我也是新手,刚做的,动态注册
//import com.borland.*;
import javax.crypto.*;
import javax.crypto.NoSuchPaddingException;
import java.security.Security;
import java.security.NoSuchAlgorithmException;public class Encrypt {
String encrypt_type="DES";//DES/ECB/PKCS5Padding
KeyGenerator kg = null;
SecretKey key = null;
public Encrypt() {
Security.addProvider( //jce注册
new com.sun.crypto.provider.SunJCE());
}
public static void main(String[] args) { Encrypt et = new Encrypt();
et.initEncrtpt() ;
byte[] data="1o1o99".getBytes() ;
byte[] result=null;
byte[] original =null;
result=et.encrypt(data) ;
original=et.unencrypt(result) ;
System.out.println(data.length);
System.out.println(result.length);
System.out.println(original.length);
} public void setEncrypt_type(String type){
this.encrypt_type =type;
} public void initEncrtpt(){
try{
kg = KeyGenerator.getInstance(encrypt_type);
key = kg.generateKey();
}catch(Exception e){
System.out.println(e.toString());
}
} public byte[] encrypt(byte[] data){
byte[] result=null;
try{
Cipher cipher = Cipher.getInstance(encrypt_type);
cipher.init(Cipher.ENCRYPT_MODE, key);
result=cipher.doFinal(data);
}catch(Exception e){
System.out.println(e.toString()) ;
}
return result;
} public byte[] unencrypt(byte[] result){
byte[] original=null;
try{ Cipher cipher = Cipher.getInstance(encrypt_type);
cipher.init(Cipher.DECRYPT_MODE, key);
original = cipher.doFinal(result);
}catch(Exception e){
System.out.println(e.toString()) ;
}
return original;
}
}我也是新手,刚做的,动态注册
随机生成的,那就是自己的密钥。可以放到本地
你说的密钥应该是权限的管理吧?
问题1. 那当用户输入密码时如何与数据库里加密过的文本相比较?