我是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