當前位置:首頁 » 密碼管理 » des加密破解

des加密破解

發布時間: 2022-04-12 07:36:43

java des 加密 解密 密鑰隨機取得方法

java DES 加密 解密 生成隨機密鑰
舉例說明:
//保存生成的key
public static void saveDesKey() {
try {
SecureRandom sr = new SecureRandom();
// 選擇的DES演算法生成一個KeyGenerator對象
KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(sr);
// 相對路徑 需要新建 conf 文件夾
// String fileName = "conf/DesKey.xml";
// 絕對路徑
String fileName = "d:/DesKey.xml";
FileOutputStream fos = new FileOutputStream(fileName);
ObjectOutputStream oos = new ObjectOutputStream(fos);
// 生成密鑰
Key key = kg.generateKey();
oos.writeObject(key);
oos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//獲取生成的key
public static Key getKey() {
Key kp = null;
try {
// 相對路徑 需要新建 conf 文件夾
// String fileName = "conf/DesKey.xml";
// InputStream is = Encrypt.class.getClassLoader().getResourceAsStream(fileName);
// 絕對路徑
String fileName = "d:/DesKey.xml";
FileInputStream is = new FileInputStream(fileName);
ObjectInputStream oos = new ObjectInputStream(is);
kp = (Key) oos.readObject();
oos.close();
} catch (Exception e) {
e.printStackTrace();
}
return kp;
}
//加密開始
public static void encrypt(String file, String dest) throws Exception {
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, getKey());
InputStream is = new FileInputStream(file);
OutputStream out = new FileOutputStream(dest);
CipherInputStream cis = new CipherInputStream(is, cipher);
byte[] buffer = new byte[1024];
int r;
while ((r = cis.read(buffer)) > 0) {
out.write(buffer, 0, r);
}
cis.close();
is.close();
out.close();
}
//解密開始
public static void decrypt(String file, String dest) throws Exception {
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, getKey());
InputStream is = new FileInputStream(file);
OutputStream out = new FileOutputStream(dest);
CipherOutputStream cos = new CipherOutputStream(out, cipher);
byte[] buffer = new byte[1024];
int r;
while ((r = is.read(buffer)) >= 0) {
cos.write(buffer, 0, r);
}
cos.close();
out.close();
is.close();
}
}
//des加密主方法
public class DES {
public static void main(String[] args) throws Exception {
Encrypt.saveDesKey();
System.out.println("生成key");
Encrypt.getKey();
System.out.println("獲取key");
Encrypt.encrypt("d:\\hello.txt", "d:\\encrypt.txt");
System.out.println("加密");
Encrypt.decrypt("d:\\encrypt.txt", "d:\\decrypt.txt");
System.out.println("解密");
}
以上方法親測可用。

② 如何用C#實現DES加密解密

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.IO;
usingSystem.Security.Cryptography;

namespaceSens.Security
{
#region<class-hDES>
publicclassHDES
{
#regionprivatefield
///<summary>
///密鑰加密演算法,默認為SHA1
///</summary>
privateHashAlgorithmKeyHash;

privateList<int>supportedKeySize;

privateEncoding_encoding=Encoding.Default;

privateDESdes;
#endregion

#regionconstructor
publicHDES(stringkey,DESdes)
{
if(des==null)
thrownewException("des不能為null");
else
this.des=des;
if(string.IsNullOrEmpty(key))
thrownewException("密鑰不能為空");
//獲取支持的密鑰長度
this.supportedKeySize=newList<int>(SupportedKeySize);
//初始化默認的key的加密方式
this.KeyHash=SHA1.Create();
this.StringKey=key;
}

#endregion

#regionpublicproperties
///<summary>
///獲取或設置文本編碼的方式
///</summary>
publicEncodingencoding
{
set{_encoding=value==null?Encoding.Default:value;}
get{return_encoding;}
}
///<summary>
///通過字元串設置密鑰
///</summary>
publicstringStringKey
{
set
{
if(string.IsNullOrEmpty(value))
thrownewException("密鑰不能為空");
byte[]keyHash=KeyHash.ComputeHash(encoding.GetBytes(value));
byte[]tmp=newbyte[8];
for(inti=0;i<8;i++)
{
tmp[i]=keyHash[i];
}
this.Key=tmp;
for(inti=8;i<16;i++)
{
tmp[i-8]=keyHash[i];
}
this.IV=tmp;
}
}
///<summary>
///
///</summary>
publicbyte[]Key
{
set
{
if(!supportedKeySize.Contains(value.Length*8))
thrownewException("密鑰長度不對");
this.des.Key=value;
}
get{returnthis.Key;}
}
///<summary>
///設置對稱加密演算法的初始化向量
///</summary>
publicbyte[]IV
{
set
{
if(!supportedKeySize.Contains(value.Length*8))
thrownewException("向量長度不對");
this.des.IV=value;
}
get{returnthis.IV;}
}
///<summary>
///獲取密鑰大小
///</summary>
publicintKeySize
{
get{returndes.KeySize;}
}
///<summary>
///獲取支持的密鑰大小
///</summary>
publicKeySizes[]LegalKeySizes
{
get{returndes.LegalKeySizes;}
}
///<summary>
///獲取支持的塊大小
///</summary>
publicKeySizes[]LegalBlockSizes
{
get{returndes.LegalBlockSizes;}


}
///<summary>
///獲取支持的密鑰大小
///</summary>
publicint[]SupportedKeySize
{
get
{
List<int>tmp=newList<int>();
intstep=0;
foreach(KeySizesitemindes.LegalKeySizes)
{
if(item.SkipSize==0)
if(item.MaxSize==item.MinSize)
step=item.MaxSize;
else
step=item.MaxSize-item.MinSize;
else
step=item.SkipSize;

for(inti=item.MinSize;i<=item.MaxSize;i+=step)
{
if(!tmp.Contains(i))
tmp.Add(i);
}
}
returntmp.ToArray();
}

}
#endregion

#regionpublicmethods
#region加解密字元串
///<summary>
///加密字元串
///</summary>
///<paramname="scr"></param>
///<returns></returns>
publicstringEncryptString(stringscr)
{

MemoryStreamms=newMemoryStream();
CryptoStreamcs=newCryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);
byte[]inputByteArray=encoding.GetBytes(scr);
cs.Write(inputByteArray,0,inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilderret=newStringBuilder();
foreach(bytebinms.ToArray())
{
ret.AppendFormat("{0:X2}",b);
}
returnret.ToString();
}
///<summary>
///解密字元串
///</summary>
///<paramname="scr"></param>
///<returns></returns>
publicstringDecryptString(stringscr)
{
byte[]inputByteArray=newbyte[scr.Length/2];
for(intx=0;x<scr.Length/2;x++)
{
inti=(System.Convert.ToInt32(scr.Substring(x*2,2),16));
inputByteArray[x]=(byte)i;
}
MemoryStreamms=newMemoryStream();
CryptoStreamcs=newCryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray,0,inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilderret=newStringBuilder();
returnencoding.GetString(ms.ToArray());
}
#endregion

#region加解密文件
///<summary>
///加密文件
///</summary>
///<paramname="filePath">要加密的文件位置</param>
///<paramname="savePath">加密後文件保存到的位置</param>
///<returns></returns>
publicboolEncryptFile(stringfilePath,stringsavePath)
{
FileStreamfs=File.OpenRead(filePath);
byte[]inputByteArray=newbyte[fs.Length];
fs.Read(inputByteArray,0,(int)fs.Length);
fs.Close();

MemoryStreamms=newMemoryStream();
CryptoStreamcs=newCryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray,0,inputByteArray.Length);
cs.FlushFinalBlock();
fs=File.OpenWrite(savePath);
foreach(bytebinms.ToArray())
{
fs.WriteByte(b);
}
fs.Close();
cs.Close();
ms.Close();
returntrue;
}
///<summary>
///解密文件
///</summary>
///<paramname="filePath">要解密的文件</param>
///<paramname="savePath">解密後保存到的位置</param>
///<paramname="keyStr"></param>
///<returns></returns>
publicboolDecryptFile(stringfilePath,stringsavePath)
{
FileStreamfs=File.OpenRead(filePath);
byte[]inputByteArray=newbyte[fs.Length];
fs.Read(inputByteArray,0,(int)fs.Length);
fs.Close();

MemoryStreamms=newMemoryStream();
CryptoStreamcs=newCryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write);
cs.Write(inputByteArray,0,inputByteArray.Length);
cs.FlushFinalBlock();
fs=File.OpenWrite(savePath);
foreach(bytebinms.ToArray())
{
fs.WriteByte(b);
}
fs.Close();
cs.Close();
ms.Close();
returntrue;
}
#endregion
#endregion
}
#endregion
}

③ 使用des對文件加密後怎麼解密

您好,一般來說在線加密工具都是網頁版的,des加密需要加密前明文和加密密鑰,在網頁的控制項上填寫好對應信息之後,點擊加密按鈕一般就可以看到加密後的加密結果。

④ 請教DES演算法的解密

DES演算法處理的數據對象是一組64比特的明文串。設該明文串為m=m1m2…m64 (mi=0或1)。明文串經過64比特的密鑰K來加密,最後生成長度為64比特的密文E。其加密過程圖示如下:

DES演算法加密過程
對DES演算法加密過程圖示的說明如下:待加密的64比特明文串m,經過IP置換後,得到的比特串的下標列表如下:

IP 58 50 42 34 26 18 10 2
60 52 44 36 28 20 12 4
62 54 46 38 30 22 14 6
64 56 48 40 32 24 16 8
57 49 41 33 25 17 9 1
59 51 43 35 27 19 11 3
61 53 45 37 29 21 13 5
63 55 47 39 31 23 15 7

該比特串被分為32位的L0和32位的R0兩部分。R0子密鑰K1(子密鑰的生成將在後面講)經過變換f(R0,K1)(f變換將在下面講)輸出32位的比特串f1,f1與L0做不進位的二進制加法運算。運算規則為:

f1與L0做不進位的二進制加法運算後的結果賦給R1,R0則原封不動的賦給L1。L1與R0又做與以上完全相同的運算,生成L2,R2…… 一共經過16次運算。最後生成R16和L16。其中R16為L15與f(R15,K16)做不進位二進制加法運算的結果,L16是R15的直接賦值。

R16與L16合並成64位的比特串。值得注意的是R16一定要排在L16前面。R16與L16合並後成的比特串,經過置換IP-1後所得比特串的下標列表如下:
IP-1 40 8 48 16 56 24 64 32
39 7 47 15 55 23 63 31
38 6 46 14 54 22 62 30
37 5 45 13 53 21 61 29
36 4 44 12 52 20 60 28
35 3 43 11 51 19 59 27
34 2 42 10 50 18 58 26
33 1 41 9 49 17 57 25

經過置換IP-1後生成的比特串就是密文e.。
下面再講一下變換f(Ri-1,Ki)。
它的功能是將32比特的輸入再轉化為32比特的輸出。其過程如圖所示:

對f變換說明如下:輸入Ri-1(32比特)經過變換E後,膨脹為48比特。膨脹後的比特串的下標列表如下:

E: 32 1 2 3 4 5
4 5 6 7 8 9
8 9 10 11 12 13
12 13 14 15 16 17
16 17 18 19 20 21
20 21 22 23 24 25
24 25 26 27 28 29
28 29 30 31 32 31

膨脹後的比特串分為8組,每組6比特。各組經過各自的S盒後,又變為4比特(具體過程見後),合並後又成為32比特。該32比特經過P變換後,其下標列表如下:

P: 16 7 20 21
29 12 28 17
1 15 23 26
5 18 31 10
2 8 24 14
32 27 3 9
19 13 30 6
22 11 4 25

經過P變換後輸出的比特串才是32比特的f (Ri-1,Ki)。

⑤ 如何使用JAVA實現對字元串的DES加密和解密

java加密字元串可以使用des加密演算法,實例如下:
package test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.*;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
/**
* 加密解密
*
* @author shy.qiu
* @since http://blog.csdn.net/qiushyfm
*/
public class CryptTest {
/**
* 進行MD5加密
*
* @param info
* 要加密的信息
* @return String 加密後的字元串
*/
public String encryptToMD5(String info) {
byte[] digesta = null;
try {
// 得到一個md5的消息摘要
MessageDigest alga = MessageDigest.getInstance("MD5");
// 添加要進行計算摘要的信息
alga.update(info.getBytes());
// 得到該摘要
digesta = alga.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// 將摘要轉為字元串
String rs = byte2hex(digesta);
return rs;
}
/**
* 進行SHA加密
*
* @param info
* 要加密的信息
* @return String 加密後的字元串
*/
public String encryptToSHA(String info) {
byte[] digesta = null;
try {
// 得到一個SHA-1的消息摘要
MessageDigest alga = MessageDigest.getInstance("SHA-1");
// 添加要進行計算摘要的信息
alga.update(info.getBytes());
// 得到該摘要
digesta = alga.digest();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// 將摘要轉為字元串
String rs = byte2hex(digesta);
return rs;
}
// //////////////////////////////////////////////////////////////////////////
/**
* 創建密匙
*
* @param algorithm
* 加密演算法,可用 DES,DESede,Blowfish
* @return SecretKey 秘密(對稱)密鑰
*/
public SecretKey createSecretKey(String algorithm) {
// 聲明KeyGenerator對象
KeyGenerator keygen;
// 聲明 密鑰對象
SecretKey deskey = null;
try {
// 返回生成指定演算法的秘密密鑰的 KeyGenerator 對象
keygen = KeyGenerator.getInstance(algorithm);
// 生成一個密鑰
deskey = keygen.generateKey();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
// 返回密匙
return deskey;
}
/**
* 根據密匙進行DES加密
*
* @param key
* 密匙
* @param info
* 要加密的信息
* @return String 加密後的信息
*/
public String encryptToDES(SecretKey key, String info) {
// 定義 加密演算法,可用 DES,DESede,Blowfish
String Algorithm = "DES";
// 加密隨機數生成器 (RNG),(可以不寫)
SecureRandom sr = new SecureRandom();
// 定義要生成的密文
byte[] cipherByte = null;
try {
// 得到加密/解密器
Cipher c1 = Cipher.getInstance(Algorithm);
// 用指定的密鑰和模式初始化Cipher對象
// 參數:(ENCRYPT_MODE, DECRYPT_MODE, WRAP_MODE,UNWRAP_MODE)
c1.init(Cipher.ENCRYPT_MODE, key, sr);
// 對要加密的內容進行編碼處理,
cipherByte = c1.doFinal(info.getBytes());
} catch (Exception e) {
e.printStackTrace();
}
// 返回密文的十六進制形式
return byte2hex(cipherByte);
}
/**
* 根據密匙進行DES解密
*
* @param key
* 密匙
* @param sInfo
* 要解密的密文
* @return String 返回解密後信息
*/
public String decryptByDES(SecretKey key, String sInfo) {
// 定義 加密演算法,
String Algorithm = "DES";
// 加密隨機數生成器 (RNG)
SecureRandom sr = new SecureRandom();
byte[] cipherByte = null;
try {
// 得到加密/解密器
Cipher c1 = Cipher.getInstance(Algorithm);
// 用指定的密鑰和模式初始化Cipher對象
c1.init(Cipher.DECRYPT_MODE, key, sr);
// 對要解密的內容進行編碼處理
cipherByte = c1.doFinal(hex2byte(sInfo));
} catch (Exception e) {
e.printStackTrace();
}
// return byte2hex(cipherByte);
return new String(cipherByte);
}
// /////////////////////////////////////////////////////////////////////////////
/**
* 創建密匙組,並將公匙,私匙放入到指定文件中
*
* 默認放入mykeys.bat文件中
*/
public void createPairKey() {
try {
// 根據特定的演算法一個密鑰對生成器
KeyPairGenerator keygen = KeyPairGenerator.getInstance("DSA");
// 加密隨機數生成器 (RNG)
SecureRandom random = new SecureRandom();
// 重新設置此隨機對象的種子
random.setSeed(1000);
// 使用給定的隨機源(和默認的參數集合)初始化確定密鑰大小的密鑰對生成器
keygen.initialize(512, random);// keygen.initialize(512);
// 生成密鑰組
KeyPair keys = keygen.generateKeyPair();
// 得到公匙
PublicKey pubkey = keys.getPublic();
// 得到私匙
PrivateKey prikey = keys.getPrivate();
// 將公匙私匙寫入到文件當中
doObjToFile("mykeys.bat", new Object[] { prikey, pubkey });
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
/**
* 利用私匙對信息進行簽名 把簽名後的信息放入到指定的文件中
*
* @param info
* 要簽名的信息
* @param signfile
* 存入的文件
*/
public void signToInfo(String info, String signfile) {
// 從文件當中讀取私匙
PrivateKey myprikey = (PrivateKey) getObjFromFile("mykeys.bat", 1);
// 從文件中讀取公匙
PublicKey mypubkey = (PublicKey) getObjFromFile("mykeys.bat", 2);
try {
// Signature 對象可用來生成和驗證數字簽名
Signature signet = Signature.getInstance("DSA");
// 初始化簽署簽名的私鑰
signet.initSign(myprikey);
// 更新要由位元組簽名或驗證的數據
signet.update(info.getBytes());
// 簽署或驗證所有更新位元組的簽名,返回簽名
byte[] signed = signet.sign();
// 將數字簽名,公匙,信息放入文件中
doObjToFile(signfile, new Object[] { signed, mypubkey, info });
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 讀取數字簽名文件 根據公匙,簽名,信息驗證信息的合法性
*
* @return true 驗證成功 false 驗證失敗
*/
public boolean validateSign(String signfile) {
// 讀取公匙
PublicKey mypubkey = (PublicKey) getObjFromFile(signfile, 2);
// 讀取簽名
byte[] signed = (byte[]) getObjFromFile(signfile, 1);
// 讀取信息
String info = (String) getObjFromFile(signfile, 3);
try {
// 初始一個Signature對象,並用公鑰和簽名進行驗證
Signature signetcheck = Signature.getInstance("DSA");
// 初始化驗證簽名的公鑰
signetcheck.initVerify(mypubkey);
// 使用指定的 byte 數組更新要簽名或驗證的數據
signetcheck.update(info.getBytes());
System.out.println(info);
// 驗證傳入的簽名
return signetcheck.verify(signed);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 將二進制轉化為16進制字元串
*
* @param b
* 二進制位元組數組
* @return String
*/
public 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;
}
}
return hs.toUpperCase();
}
/**
* 十六進制字元串轉化為2進制
*
* @param hex
* @return
*/
public byte[] hex2byte(String hex) {
byte[] ret = new byte[8];
byte[] tmp = hex.getBytes();
for (int i = 0; i < 8; i++) {
ret[i] = uniteBytes(tmp[i * 2], tmp[i * 2 + 1]);
}
return ret;
}
/**
* 將兩個ASCII字元合成一個位元組; 如:"EF"--> 0xEF
*
* @param src0
* byte
* @param src1
* byte
* @return byte
*/
public static byte uniteBytes(byte src0, byte src1) {
byte _b0 = Byte.decode("0x" + new String(new byte[] { src0 }))
.byteValue();
_b0 = (byte) (_b0 << 4);
byte _b1 = Byte.decode("0x" + new String(new byte[] { src1 }))
.byteValue();
byte ret = (byte) (_b0 ^ _b1);
return ret;
}
/**
* 將指定的對象寫入指定的文件
*
* @param file
* 指定寫入的文件
* @param objs
* 要寫入的對象
*/
public void doObjToFile(String file, Object[] objs) {
ObjectOutputStream oos = null;
try {
FileOutputStream fos = new FileOutputStream(file);
oos = new ObjectOutputStream(fos);
for (int i = 0; i < objs.length; i++) {
oos.writeObject(objs[i]);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
oos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 返回在文件中指定位置的對象
*
* @param file
* 指定的文件
* @param i
* 從1開始
* @return
*/
public Object getObjFromFile(String file, int i) {
ObjectInputStream ois = null;
Object obj = null;
try {
FileInputStream fis = new FileInputStream(file);
ois = new ObjectInputStream(fis);
for (int j = 0; j < i; j++) {
obj = ois.readObject();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return obj;
}
/**
* 測試
*
* @param args
*/
public static void main(String[] args) {
CryptTest jiami = new CryptTest();
// 執行MD5加密"Hello world!"
System.out.println("Hello經過MD5:" + jiami.encryptToMD5("Hello"));
// 生成一個DES演算法的密匙
SecretKey key = jiami.createSecretKey("DES");
// 用密匙加密信息"Hello world!"
String str1 = jiami.encryptToDES(key, "Hello");
System.out.println("使用des加密信息Hello為:" + str1);
// 使用這個密匙解密
String str2 = jiami.decryptByDES(key, str1);
System.out.println("解密後為:" + str2);
// 創建公匙和私匙
jiami.createPairKey();
// 對Hello world!使用私匙進行簽名
jiami.signToInfo("Hello", "mysign.bat");
// 利用公匙對簽名進行驗證。
if (jiami.validateSign("mysign.bat")) {
System.out.println("Success!");
} else {
System.out.println("Fail!");
}
}
}

⑥ DES加密演算法的破解是怎麼回事

DES 被證明是可以破解的,明文+密鑰=密文,這個公式只要知道任何兩個,就可以推導出第三個。

凌科芯安公司專門從事加密晶元,對破解有一定的了解,如果需要了解加密晶元的詳細情況,請咨詢凌科芯安公司

⑦ 怎麼解密DES文件

數據加密演算法(Data Encryption Algorithm,DEA)的數據加密標准(Data Encryption Standard,DES)是規范的描述,它出自 IBM 的研究工作,並在 1997 年被美國政府正式採納。它很可能是使用最廣泛的秘鑰系統,特別是在保護金融數據的安全中,最初開發的 DES 是嵌入硬 件中的。通常,自動取款機(Automated Teller Machine,ATM)都使用 DES。
DES的解密一般都很麻煩,也很難,建議你去下載一個破解密碼的工具試試看行不行。

⑧ Des加密解密方法 用java C#和C++三種方式實現

Solaris下的系統,有一個用C做的加密工具,調用Sunwcry的des(1)對文件進行加密,然後在java中對文件進行解密。java中用的是標準的DES/CBC/NoPadding演算法,可是解密後發現開頭有8byte的數據出錯了,請高人指點一下。

cbc_encrypt.c : 加密用的C程序

cbc_decrypt.c:解密用的C程序

TestDescbc.java:解密用的java程序

Test01.dat原始文件
Test03.dat cbc_encrypt加密後的文件
Test05.dat cbc_decrypt解密後的文件

Test06.dat TestDescbc解密後的文件

⑨ 已知DES加密前的明文和加密後的密文,能否反向破解出DES密鑰

不能!除非你用好配置計算機暴力破解。
DES演算法你知道的,打個比方:就像你知道原文件數據是100,被加密後變成1000了,你也知道他是用加法得到的1000,但密鑰你不知道,就像到底是100+900=1000,還是101+899=1000,……,所以沒辦法把密文2000還原成真正的明文。這只是個簡單的比方,當然實際運算要比這復雜的多。
被公司的企業版加密軟體加密了的文件,帶回家效果就是:office打開亂碼、PDF打開格式錯誤、CAD圖形文件無效……你加球球:把酒散酒斯兒另霸酒。還可以解除只讀、打開次數、使用期限的或被製作成exe格式的外發文件。

⑩ 如何解DES加密的文件

一個用DES來加密、解密的類
http://www.javanb.com/java/1/17816.html

import java.security.*;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;

/**
* 字元串工具集合
* @author Liudong
*/
public class StringUtils {

private static final String PASSWORD_CRYPT_KEY = "__jDlog_";
private final static String DES = "DES";

/**
* 加密
* @param src 數據源
* @param key 密鑰,長度必須是8的倍數
* @return 返回加密後的數據
* @throws Exception
*/
public static byte[] encrypt(byte[] src, byte[] key)throws Exception {
//DES演算法要求有一個可信任的隨機數源
SecureRandom sr = new SecureRandom();
// 從原始密匙數據創建DESKeySpec對象
DESKeySpec dks = new DESKeySpec(key);
// 創建一個密匙工廠,然後用它把DESKeySpec轉換成
// 一個SecretKey對象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher對象實際完成加密操作
Cipher cipher = Cipher.getInstance(DES);
// 用密匙初始化Cipher對象
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
// 現在,獲取數據並加密
// 正式執行加密操作
return cipher.doFinal(src);
}

/**
* 解密
* @param src 數據源
* @param key 密鑰,長度必須是8的倍數
* @return 返回解密後的原始數據
* @throws Exception
*/
public static byte[] decrypt(byte[] src, byte[] key)throws Exception {
// DES演算法要求有一個可信任的隨機數源
SecureRandom sr = new SecureRandom();
// 從原始密匙數據創建一個DESKeySpec對象
DESKeySpec dks = new DESKeySpec(key);
// 創建一個密匙工廠,然後用它把DESKeySpec對象轉換成
// 一個SecretKey對象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher對象實際完成解密操作
Cipher cipher = Cipher.getInstance(DES);
// 用密匙初始化Cipher對象
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
// 現在,獲取數據並解密
// 正式執行解密操作
return cipher.doFinal(src);
}
/**
* 密碼解密
* @param data
* @return
* @throws Exception
*/
public final static String decrypt(String data){
try {
return new String(decrypt(hex2byte(data.getBytes()),
PASSWORD_CRYPT_KEY.getBytes()));
}catch(Exception e) {
}
return null;
}
/**
* 密碼加密
* @param password
* @return
* @throws Exception
*/
public final static String encrypt(String password){
try {
return byte2hex(encrypt(password.getBytes(),PASSWORD_CRYPT_KEY.getBytes())); }catch(Exception e) {
}
return null;
}

比較長, 轉了一部分.
參考資料:http://www.javanb.com/java/1/17816.html

熱點內容
lockjava 發布:2025-05-17 13:02:08 瀏覽:310
只狼和看門狗哪個配置高 發布:2025-05-17 12:50:21 瀏覽:205
扁桃玩的伺服器地址 發布:2025-05-17 12:18:25 瀏覽:511
u盤上傳歌 發布:2025-05-17 12:14:51 瀏覽:615
入門c語言設計 發布:2025-05-17 12:08:31 瀏覽:41
c3演算法 發布:2025-05-17 12:04:19 瀏覽:365
phprecv 發布:2025-05-17 11:55:00 瀏覽:616
福建時鍾監控網關伺服器雲主機 發布:2025-05-17 11:54:28 瀏覽:253
c資料庫壓縮 發布:2025-05-17 11:39:22 瀏覽:965
安卓手機如何連接音響功放 發布:2025-05-17 11:37:48 瀏覽:965