簡體   English   中英

使用 GUID 進行 RSA 加密和解密

[英]RSA Encryption and Decryption using GUID

任何人都可以使用公鑰和私鑰幫助我進行 RSA 加密和解密

RSA是一種非對稱加密算法。 這意味着它需要一個公鑰和私鑰來加密和解密信息。 這通常使用隨機生成的密鑰來完成。

在技術上是否可以從 passphrases 生成 RSA 密鑰,盡管這似乎不是您真正想要的。

GUID是 128 位 integer(16 字節),可在需要唯一標識符的所有計算機和網絡中使用。 這樣的標識符被復制的概率非常低。

這可以以某些流行的對稱加密算法(如 AES )的形式使用,以僅使用 1 個密鑰加密數據,特別是因為 GUID 與 AES 128 位密鑰的長度相似。 (盡管實際使用它可能需要一些技巧,因為某些加密算法需要遵循某種模式來為其密鑰)編輯:我剛剛測試過,您可以將 GUID 用作 128 位 AES 加密密鑰,而無需花哨的東西。

// create the string that we are going to encrypt
string original = "hello world";

// get a new GUID to use as an encryption key
Guid id =  Guid.NewGuid();

using (Aes myAes = Aes.Create())
{
    // make sure the key size matches what a GUID is (128 bits)
    myAes.KeySize = 128;

    // set the encryption key to use the GUID instead
    myAes.Key = id.ToByteArray();

    // Encrypt the string to an array of bytes.
    byte[] encrypted = EncryptStringToBytes_Aes(original, myAes.Key, myAes.IV);

    // make sure bytes are encrypted
    Console.WriteLine(string.Join(", ", encrypted));

    // Decrypt the bytes to a string.
    string roundtrip = DecryptStringFromBytes_Aes(encrypted, myAes.Key, myAes.IV);

    //Display the original data and the decrypted data.
    Console.WriteLine("Original:   {0}", original);
    Console.WriteLine("Round Trip: {0}", roundtrip);
}

話雖如此,為生產和 OPSEC 環境實施有效的加密方案是一項嚴肅的工作,需要大量信息、背景和對當前加密環境的深刻理解。 我既沒有消息靈通,也沒有受過足夠的教育,無法了解正確的加密標准、技術,以及什么是有效加密,什么是不可以使用的。 在為嚴肅的項目實施此代碼之前,請完成您自己的個人研究。

暫無
暫無

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

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