加密解密 使用對稱密碼加密檔案

2022-07-05 11:54:09 字數 610 閱讀 5774

造冰箱的大熊貓@cnblogs 2019/5/24

1、加密

gpg -c file-to-be-encrypted

其中,「file-to-be-encrypted」 是待加密檔案。gpg只能加密檔案,不能加密資料夾。要對資料夾進行加密,需先將資料夾進行打包。加密後的檔案為「file-to-be-encrypted.gpg」

2、解密

gpg -o file-readable -d file-to-be-encrypted.gpg

其中,「file-to-be-encrypted.gpg」 是待解密檔案。「-o file-readble」表示將解密結果儲存為檔案「file-readable」。如果沒有這個-o(小寫字母o),則gpg將解密結果輸出到命令列。

2019/5/25補充:有個小問題,gpg應該有某種緩衝機制,用gpg加密的檔案,在一定時間內在本機上解密,不提示使用者輸入密碼,直接解開。怎麼遮蔽這個緩衝機制,改天仔細研究下gpg文件再說。

參考

[1] gpg官網

RSA 加密解密使用例項

本文不討論rsa加密解密本身,只記錄使用方法及遇到的坑,rsa原理及注意事項可在網上查詢。背景 公司的乙個需求,要求對接客戶的乙個平台,通訊方式為mqtt,資料報含token及json內容,在通訊過程中傳送的mqtt資訊必須帶上token,這個token是要從客戶平台獲取,通過http協議,post...

對稱加密 解密

加密 public static class encrypting 使用對稱演算法加密 public static string symmetricencrypts string str 如需指定加密演算法,可在create 引數中指定字串 create 方法中的引數可以是 des rc2 syst...

對稱加密解密

幫助類 public class cryptohelper encryptor provider.createencryptor decryptor provider.createdecryptor initializes a new instance of the class.金鑰 public ...