当前位置: 技术问答>java相关
加密解密,脑袋都搞大了,大伙帮忙看看!
来源: 互联网 发布时间:2015-06-05
本文导语: 下面是两个测试程序,(均是从网上找到的,^_^)。 测试程序一: package encryption; /** * Title: * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */ import java.io.*; import java.math.BigInteg...
下面是两个测试程序,(均是从网上找到的,^_^)。
测试程序一:
package encryption;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/
import java.io.*;
import java.math.BigInteger;
import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
public class En1 {
public En1() {
KeyGenerator keygen;
SecretKey desKey;
Cipher desCipher;
try{
//DES,DESede,PBEWithMD5AndDES,Blowfish
//Generating a Key
// keygen = KeyGenerator.getInstance("DES");
// keygen = KeyGenerator.getInstance("DESede");
keygen = KeyGenerator.getInstance("Blowfish");
desKey = keygen.generateKey();
System.out.println(
desKey.getEncoded().toString()
);
// Create the cipher
// desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
// desCipher = Cipher.getInstance("DESede");
desCipher = Cipher.getInstance("Blowfish");
// Our cleartext
byte[] cleartext = "This is just an example:邢战军".getBytes();
StringBuffer StrBuf = new StringBuffer();
for(int i=0,j=cleartext.length;i
测试程序一:
package encryption;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/
import java.io.*;
import java.math.BigInteger;
import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
public class En1 {
public En1() {
KeyGenerator keygen;
SecretKey desKey;
Cipher desCipher;
try{
//DES,DESede,PBEWithMD5AndDES,Blowfish
//Generating a Key
// keygen = KeyGenerator.getInstance("DES");
// keygen = KeyGenerator.getInstance("DESede");
keygen = KeyGenerator.getInstance("Blowfish");
desKey = keygen.generateKey();
System.out.println(
desKey.getEncoded().toString()
);
// Create the cipher
// desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
// desCipher = Cipher.getInstance("DESede");
desCipher = Cipher.getInstance("Blowfish");
// Our cleartext
byte[] cleartext = "This is just an example:邢战军".getBytes();
StringBuffer StrBuf = new StringBuffer();
for(int i=0,j=cleartext.length;i