簡體   English   中英

如何使用 C# 從 Kleopatra 訪問 PGP 密鑰

[英]How to access PGP keys from Kleopatra using C#

我有一個用 Kleopatra 創建的 PGP 密鑰對,我想知道如何使用 C# 訪問它?

我正在使用PgpCore庫來解密文件,但似乎我需要將密鑰文件提供給它,但我不知道它存儲在機器上的位置或訪問它的最佳方式。

有什么方法可以用證書的 ID 查詢 Kleopatra 來檢索密鑰?

超級遲到,但我自己正在經歷這個。 我認為您必須導出密鑰,然后指向存儲它們以在 C# 中使用的文件路徑

克利奧帕特拉

導出私鑰:右鍵單擊並選擇“備份密鑰”

導出公鑰:右鍵單擊“導出密鑰”以備份公鑰。

用於加密和解密的 PGPCore 代碼

使用公鑰 加密

// Load keys
EncryptionKeys encryptionKeys;
using (Stream publicKeyStream = new FileStream(@"C:\TEMP\Keys\public.asc", FileMode.Open))
    encryptionKeys = new EncryptionKeys(publicKeyStream);

PGP pgp = new PGP(encryptionKeys);

// Reference input/output files
using (FileStream inputFileStream = new FileStream(@"C:\TEMP\Content\content.txt", FileMode.Open))
using (Stream outputFileStream = File.Create(@"C:\TEMP\Content\encrypted.pgp"))
    // Encrypt
    await pgp.EncryptStreamAsync(inputFileStream, outputFileStream);

使用私鑰和密碼 解密

// Load keys
EncryptionKeys encryptionKeys;
using (Stream privateKeyStream = new FileStream(@"C:\TEMP\Keys\private.asc", FileMode.Open))
    encryptionKeys = new EncryptionKeys(privateKeyStream, "password");

PGP pgp = new PGP(encryptionKeys);

// Reference input/output files
using (FileStream inputFileStream = new FileStream(@"C:\TEMP\Content\encryptedContent.pgp", FileMode.Open))
using (Stream outputFileStream = File.Create(@"C:\TEMP\Content\decrypted.txt"))
    // Decrypt
    await pgp.DecryptStreamAsync(inputFileStream, outputFileStream);

明明把文件路徑改成對應的key路徑, , encrypt=public,decrypt=private

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM