|
Dieser Artikel wurde manuell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen.
|
Übersetzung
Original
|
Rfc2898DeriveBytes-Klasse
System.Security.Cryptography.DeriveBytes
System.Security.Cryptography.Rfc2898DeriveBytes
Assembly: mscorlib (in mscorlib.dll)
Der Rfc2898DeriveBytes-Typ macht die folgenden Member verfügbar.
| Name | Beschreibung | |
|---|---|---|
![]() | Rfc2898DeriveBytes(String, Byte[]) | |
![]() | Rfc2898DeriveBytes(String, Int32) | |
![]() | Rfc2898DeriveBytes(Byte[], Byte[], Int32) | |
![]() | Rfc2898DeriveBytes(String, Byte[], Int32) | |
![]() | Rfc2898DeriveBytes(String, Int32, Int32) |
| Name | Beschreibung | |
|---|---|---|
![]() | IterationCount | |
![]() | Salt |
| Name | Beschreibung | |
|---|---|---|
![]() | Dispose() | |
![]() | Dispose(Boolean) | |
![]() | Equals(Object) | |
![]() | Finalize | |
![]() | GetBytes | |
![]() | GetHashCode | |
![]() | GetType | |
![]() | MemberwiseClone | |
![]() | Reset | |
![]() | ToString |
Sicherheitshinweis |
|---|
using System; using System.IO; using System.Text; using System.Security.Cryptography; public class rfc2898test { // Generate a key k1 with password pwd1 and salt salt1. // Generate a key k2 with password pwd1 and salt salt1. // Encrypt data1 with key k1 using symmetric encryption, creating edata1. // Decrypt edata1 with key k2 using symmetric decryption, creating data2. // data2 should equal data1. private const string usageText = "Usage: RFC2898 <password>\nYou must specify the password for encryption.\n"; public static void Main(string[] passwordargs) { //If no file name is specified, write usage text. if (passwordargs.Length == 0) { Console.WriteLine(usageText); } else { string pwd1 = passwordargs[0]; byte[] salt1 = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45}; //data1 can be a string or contents of a file. string data1 = "Some test data"; //The default iteration count is 1000 so the two methods use the same iteration count. int myIterations = 1000; try { Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1,myIterations); Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1); // Encrypt the data. TripleDES encAlg = TripleDES.Create(); encAlg.Key = k1.GetBytes(16); MemoryStream encryptionStream = new MemoryStream(); CryptoStream encrypt = new CryptoStream(encryptionStream, encAlg.CreateEncryptor(),CryptoStreamMode.Write); byte[] utfD1 = new System.Text.UTF8Encoding(false).GetBytes(data1); encrypt.Write(utfD1, 0, utfD1.Length); encrypt.FlushFinalBlock(); encrypt.Close(); byte[] edata1 = encryptionStream.ToArray(); k1.Reset(); // Try to decrypt, thus showing it can be round-tripped. TripleDES decAlg = TripleDES.Create(); decAlg.Key = k2.GetBytes(16); decAlg.IV = encAlg.IV; MemoryStream decryptionStreamBacking = new MemoryStream(); CryptoStream decrypt = new CryptoStream(decryptionStreamBacking,decAlg.CreateDecryptor(), CryptoStreamMode.Write); decrypt.Write(edata1, 0, edata1.Length); decrypt.Flush(); decrypt.Close(); k2.Reset(); string data2 = new UTF8Encoding(false).GetString(decryptionStreamBacking.ToArray()); if (!data1.Equals(data2)) { Console.WriteLine("Error: The two values are not equal."); } else { Console.WriteLine("The two values are equal."); Console.WriteLine("k1 iterations: {0}",k1.IterationCount); Console.WriteLine("k2 iterations: {0}",k2.IterationCount); } } catch (Exception e) { Console.WriteLine("Error: ",e); } } } }
Windows 7, Windows Vista SP1 oder höher, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core wird nicht unterstützt), Windows Server 2008 R2 (Server Core wird mit SP1 oder höher unterstützt), Windows Server 2003 SP2
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
