我是C#的初學者。到目前爲止,我知道一個public static
變量可以被任何其他類訪問,並且public static
方法中的局部變量不能被其他類訪問。所以,在這種情況下,我想要訪問Main()
方法中的所有密鑰,並對它們進行操作。我怎樣才能做到這一點?必須有一種方法。我想過使用return
,但它只會返回一個我會選擇的鍵值。有什麼方法可以一次返回多個值嗎?從Main()方法獲取對局部變量的訪問
這是代碼生成的密鑰
class keyCreation
{
public static void Key_Derivation_Function(byte[] password)
{
string salt = "12345678";
byte[] saltbyte = Encoding.UTF8.GetBytes(salt);
Console.WriteLine("Password length: " + password.Length);
Console.WriteLine("Saltbyte lenght: " + saltbyte.Length);
Rfc2898DeriveBytes keyGenerate = new Rfc2898DeriveBytes(password, saltbyte, 1000);
byte[] key1 = keyGenerate.GetBytes(16);
byte[] key2 = keyGenerate.GetBytes(32);
byte[] key3 = keyGenerate.GetBytes(16);
byte[] key4 = keyGenerate.GetBytes(32);
byte[] key5 = keyGenerate.GetBytes(16);
byte[] key6 = keyGenerate.GetBytes(16);
byte[] key7 = keyGenerate.GetBytes(32);
}
}
這是主要的方法,
class Program
{
static void Main(string[] args)
{
//user giving input
Console.WriteLine("Plaintext: ");
string plaintext = Console.ReadLine();
byte[] text = Encoding.UTF8.GetBytes(plaintext);
Console.WriteLine("Enter Password: ");
string pass = Console.ReadLine();
byte[] password = Encoding.UTF8.GetBytes(pass);
keyCreation.Key_Derivation_Function(password);
// get the keys and do something with the keys
}
}
因此,返回類型是一個方法!哇之前從來沒有見過這種類型的編碼。謝謝 – Giliweed