檔案加密解密問題

2021-08-08 05:34:24 字數 1934 閱讀 7338

public class encryption  

// 加密  

byte bytout = encryptbydes(encryptbydes(encryptbydes(bytin,  

bytk1), bytk2), bytk3);  

//string fileout = "en_"+filein.getpath(); 

string fileout = filein.getpath(); 

fileoutputstream fos = new fileoutputstream(fileout);  

for (int i = 0; i < bytout.length; i++)  

fos.close();  

} else  

;  } catch (exception e)  

}  /** 

* 解密函式 輸入: 要解密的檔案,密碼(由0-f組成,共48個字元,表示3個16位的密碼)如: 

* ad67ea2f3be6e5add368dfe03120b5df92a8fd8fec2f0746 其中:  

* ad67ea2f3be6e5ad  des密碼一 d368dfe03120b5df des密碼二 92a8fd8fec2f0746 des密碼三  

* 輸出:對輸入的檔案解密後,儲存到使用者指定的檔案中。 

*/  

public void decrypt(file filein, string skey)  

// 解密  

byte bytout = decryptbydes(decryptbydes(decryptbydes(bytin,  

bytk3), bytk2), bytk1);  

file fileout = chooser.getselectedfile(); 

fileout.createnewfile();  

fileoutputstream fos = new fileoutputstream(fileout);  

for (int i = 0; i < bytout.length; i++)  

fos.close();    

}  } catch (exception e)  

}  /** 

* 用des方法加密輸入的位元組 bytkey需為8位元組長,是加密的密碼 

* param:bytp 檔案  , bytkey 密碼 

* return: 

*/  

private byte encryptbydes(byte bytp, byte bytkey) throws exception  

/** 

* 用des方法解密輸入的位元組 bytkey需為8位元組長,是解密的密碼 

*/  

private byte decryptbydes(byte byte, byte bytkey) throws exception  

/** 

* 輸入密碼的字元形式,返回位元組陣列形式。 如輸入字串:ad67ea2f3be6e5ad 

* 返回位元組陣列: 

*/  

private byte getkeybystr(string str)  

return bret;  

}  /** 

* 計算乙個16進製制字元的10進製值 輸入:0-f 

*/  

private int getchrint(char chr)  

public string md5s(string plaintext)  

str = buf.tostring().substring(8, 24);  

} catch (nosuchalgorithmexception e)  

return str;  

}  }

加密解密檔案

1 decrypt 方法允許解密使用 encrypt 方法加密的檔案。decrypt 方法只能解密使用當前使用者帳戶加密的檔案。23 decrypt 方法要求獨佔訪問被解密的檔案,如果有其他程序正在使用該檔案,此方法將引發異常。如果檔案沒有加密,則 decrypt 將返回乙個非零值,這表示成功。45...

檔案加密解密 URl引數加密解密

sliverlight 加密解密 public static class encryption endregion region silverlight密碼解密 解密資料 加密後的字串 加密前的字串 public static string decrypt string input endregio...

linux 檔案 加密 解密

單純的檔案加密 openssl enc 加密 openssl enc des e a in input file out out file 解密 openssl enc des d a inout file out input file 方法一 用tar命令 對檔案加密壓縮和解壓 壓縮 tar zc...