package com.cube.limail.util;
贛州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書(shū)合作)期待與您的合作!
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;/**
* 加密解密類
*/
public class Eryptogram
{
private static String Algorithm ="DES";
private String key="CB7A92E3D3491964";
//定義 加密算法,可用 DES,DESede,Blowfish
static boolean debug = false ;
/**
* 構(gòu)造子注解.
*/
public Eryptogram ()
{
} /**
* 生成密鑰
* @return byte[] 返回生成的密鑰
* @throws exception 扔出異常.
*/
public static byte [] getSecretKey () throws Exception
{
KeyGenerator keygen = KeyGenerator.getInstance (Algorithm );
SecretKey deskey = keygen.generateKey ();
System.out.println ("生成密鑰:"+bytesToHexString (deskey.getEncoded ()));
if (debug ) System.out.println ("生成密鑰:"+bytesToHexString (deskey.getEncoded ()));
return deskey.getEncoded ();
} /**
* 將指定的數(shù)據(jù)根據(jù)提供的密鑰進(jìn)行加密
* @param input 需要加密的數(shù)據(jù)
* @param key 密鑰
* @return byte[] 加密后的數(shù)據(jù)
* @throws Exception
*/
public static byte [] encryptData (byte [] input ,byte [] key ) throws Exception
{
SecretKey deskey = new javax.crypto.spec.SecretKeySpec (key ,Algorithm );
if (debug )
{
System.out.println ("加密前的二進(jìn)串:"+byte2hex (input ));
System.out.println ("加密前的字符串:"+new String (input ));
} Cipher c1 = Cipher.getInstance (Algorithm );
c1.init (Cipher.ENCRYPT_MODE ,deskey );
byte [] cipherByte =c1.doFinal (input );
if (debug ) System.out.println ("加密后的二進(jìn)串:"+byte2hex (cipherByte ));
return cipherByte ;
} /**
* 將給定的已加密的數(shù)據(jù)通過(guò)指定的密鑰進(jìn)行解密
* @param input 待解密的數(shù)據(jù)
* @param key 密鑰
* @return byte[] 解密后的數(shù)據(jù)
* @throws Exception
*/
public static byte [] decryptData (byte [] input ,byte [] key ) throws Exception
{
SecretKey deskey = new javax.crypto.spec.SecretKeySpec (key ,Algorithm );
if (debug ) System.out.println ("解密前的信息:"+byte2hex (input ));
Cipher c1 = Cipher.getInstance (Algorithm );
c1.init (Cipher.DECRYPT_MODE ,deskey );
byte [] clearByte =c1.doFinal (input );
if (debug )
{
System.out.println ("解密后的二進(jìn)串:"+byte2hex (clearByte ));
System.out.println ("解密后的字符串:"+(new String (clearByte )));
} return clearByte ;
} /**
* 字節(jié)碼轉(zhuǎn)換成16進(jìn)制字符串
* @param byte[] b 輸入要轉(zhuǎn)換的字節(jié)碼
* @return String 返回轉(zhuǎn)換后的16進(jìn)制字符串
*/
public static String byte2hex (byte [] b )
{
String hs ="";
String stmp ="";
for (int n =0 ;n b.length ;n ++)
{
stmp =(java.lang.Integer.toHexString (b [n ] 0XFF ));
if (stmp.length ()==1 ) hs =hs +"0"+stmp ;
else hs =hs +stmp ;
if (n b.length -1 ) hs =hs +":";
} return hs.toUpperCase ();
}
/**
* 字符串轉(zhuǎn)成字節(jié)數(shù)組.
* @param hex 要轉(zhuǎn)化的字符串.
* @return byte[] 返回轉(zhuǎn)化后的字符串.
*/
public static byte[] hexStringToByte(String hex) {
int len = (hex.length() / 2);
byte[] result = new byte[len];
char[] achar = hex.toCharArray();
for (int i = 0; i len; i++) {
int pos = i * 2;
result[i] = (byte) (toByte(achar[pos]) 4 | toByte(achar[pos + 1]));
}
return result;
}
private static byte toByte(char c) {
byte b = (byte) "0123456789ABCDEF".indexOf(c);
return b;
}
/**
* 字節(jié)數(shù)組轉(zhuǎn)成字符串.
* @param String 要轉(zhuǎn)化的字符串.
* @return 返回轉(zhuǎn)化后的字節(jié)數(shù)組.
*/
public static final String bytesToHexString(byte[] bArray) {
StringBuffer sb = new StringBuffer(bArray.length);
String sTemp;
for (int i = 0; i bArray.length; i++) {
sTemp = Integer.toHexString(0xFF bArray[i]);
if (sTemp.length() 2)
sb.append(0);
sb.append(sTemp.toUpperCase());
}
return sb.toString();
}
/**
* 從數(shù)據(jù)庫(kù)中獲取密鑰.
* @param deptid 企業(yè)id.
* @return 要返回的字節(jié)數(shù)組.
* @throws Exception 可能拋出的異常.
*/
public static byte[] getSecretKey(long deptid) throws Exception {
byte[] key=null;
String value=null;
//CommDao dao=new CommDao();
// List list=dao.getRecordList("from Key k where k.deptid="+deptid);
//if(list.size()0){
//value=((com.csc.sale.bean.Key)list.get(0)).getKey();
value = "CB7A92E3D3491964";
key=hexStringToByte(value);
//}
if (debug)
System.out.println("密鑰:" + value);
return key;
}
public String encryptData2(String data) {
String en = null;
try {
byte[] key=hexStringToByte(this.key);
en = bytesToHexString(encryptData(data.getBytes(),key));
} catch (Exception e) {
e.printStackTrace();
}
return en;
}
public String decryptData2(String data) {
String de = null;
try {
byte[] key=hexStringToByte(this.key);
de = new String(decryptData(hexStringToByte(data),key));
} catch (Exception e) {
e.printStackTrace();
}
return de;
}
} 加密使用: byte[] key=Eryptogram.getSecretKey(deptid); //獲得鑰匙(字節(jié)數(shù)組)
byte[] tmp=Eryptogram.encryptData(password.getBytes(), key); //傳入密碼和鑰匙,獲得加密后的字節(jié)數(shù)組的密碼
password=Eryptogram.bytesToHexString(tmp); //將字節(jié)數(shù)組轉(zhuǎn)化為字符串,獲得加密后的字符串密碼解密與之差不多
1.WINZIP壓縮文件的破解 針對(duì)WINZIP壓縮文件,黑客最常使用的工具就是Elcomsoft公司的“Advanced ZIP Password Recovery”(簡(jiǎn)稱AZPR),AZPR提供了一個(gè)圖形化的用戶界面,黑客經(jīng)過(guò)幾個(gè)簡(jiǎn)單的步驟就可以破解ZIP壓縮文件包的密碼。 第一步:配置破...
md5是不可逆的,只不過(guò)用的人多了,就有人創(chuàng)建了一個(gè)md5密碼表,應(yīng)該就是傳說(shuō)中的彩虹表,蜜要是有這個(gè)表就可以了
用While和一個(gè)計(jì)數(shù)變量,以下是偽代碼
定義計(jì)數(shù)變量并歸零
定義狀態(tài)變量并歸零
while(計(jì)數(shù)變量3且狀態(tài)變量為真)
{
輸入密碼
if(密碼正確)
{
狀態(tài)變量設(shè)定為真
}
else
{
計(jì)數(shù)變量+1
密碼框清空
}
}
if(狀態(tài)變量不為真) /說(shuō)明前面的循環(huán)結(jié)束是因?yàn)檩斿e(cuò)了三次
{
提示:請(qǐng)管理員解鎖
【密碼輸入過(guò)程與上方用while循環(huán)類似】
}
else
{
(剩余操作)
}
import org.junit.Test;
public class T {
//最小長(zhǎng)度
private int min = 1;
//最大長(zhǎng)度
private int max = 10;
//準(zhǔn)備數(shù)字,大小寫(xiě)
private char[] psw = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
@Test
public void t(){
for(int i=min; i=max; i++){
permutation(psw, i);
}
}
/**
* 全排列入口
* @param array 密碼數(shù)據(jù)
* @param n 密碼長(zhǎng)度
*/
private void permutation(char[] array, int n) {
permutation("", array, n);
}
/**
*
* @param s 已生成臨時(shí)字串
* @param array 密碼數(shù)據(jù)
* @param n 剩余未生成的字符長(zhǎng)度
*/
private void permutation(String s, char[] array, int n) {
if(n == 1) {
for(int i=0; iarray.length; i++) {
//這是密碼結(jié)果
String result = s+array[i];
System.out.println(result);
}
} else {
for(int i=0; iarray.length; i++) {
permutation(s+array[i], array, n-1);
}
}
}
}
不過(guò)建議不要暴力,有針對(duì)性會(huì)好一點(diǎn)
這個(gè)算法java SDK自帶的額 參考代碼如下:
/**解密
*?@param?content??待解密內(nèi)容
*?@param?password?解密密鑰
*?@return
*/
public?static?byte[]?decrypt(byte[]?content,?String?password)?{
try?{
KeyGenerator?kgen?=?KeyGenerator.getInstance("AES");
kgen.init(128,?new?SecureRandom(password.getBytes()));
SecretKey?secretKey?=?kgen.generateKey();
byte[]?enCodeFormat?=?secretKey.getEncoded();
SecretKeySpec?key?=?new?SecretKeySpec(enCodeFormat,?"AES");
Cipher?cipher?=?Cipher.getInstance("AES");//?創(chuàng)建密碼器
cipher.init(Cipher.DECRYPT_MODE,?key);//?初始化
byte[]?result?=?cipher.doFinal(content);
return?result;?//?加密
}?catch?(NoSuchAlgorithmException?e)?{
e.printStackTrace();
}?catch?(NoSuchPaddingException?e)?{
e.printStackTrace();
}?catch?(InvalidKeyException?e)?{
e.printStackTrace();
}?catch?(IllegalBlockSizeException?e)?{
e.printStackTrace();
}?catch?(BadPaddingException?e)?{
e.printStackTrace();
}
return?null;
}
/**
*?加密
*
*?@param?content?需要加密的內(nèi)容
*?@param?password??加密密碼
*?@return
*/
public?static?byte[]?encrypt(String?content,?String?password)?{
try?{
KeyGenerator?kgen?=?KeyGenerator.getInstance("AES");
kgen.init(128,?new?SecureRandom(password.getBytes()));
SecretKey?secretKey?=?kgen.generateKey();
byte[]?enCodeFormat?=?secretKey.getEncoded();
SecretKeySpec?key?=?new?SecretKeySpec(enCodeFormat,?"AES");
Cipher?cipher?=?Cipher.getInstance("AES");//?創(chuàng)建密碼器
byte[]?byteContent?=?content.getBytes("utf-8");
cipher.init(Cipher.ENCRYPT_MODE,?key);//?初始化
byte[]?result?=?cipher.doFinal(byteContent);
return?result;?//?加密
}?catch?(NoSuchAlgorithmException?e)?{
e.printStackTrace();
}?catch?(NoSuchPaddingException?e)?{
e.printStackTrace();
}?catch?(InvalidKeyException?e)?{
e.printStackTrace();
}?catch?(UnsupportedEncodingException?e)?{
e.printStackTrace();
}?catch?(IllegalBlockSizeException?e)?{
e.printStackTrace();
}?catch?(BadPaddingException?e)?{
e.printStackTrace();
}
return?null;
}
圖像界面的話就不說(shuō)了