diff --git a/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/CPP/sample.cpp b/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/CPP/sample.cpp index a0ab9ae6252..6c79fdd960a 100644 --- a/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/CPP/sample.cpp +++ b/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/CPP/sample.cpp @@ -40,8 +40,8 @@ static void Encrypt( XmlDocument^ Doc, String^ ElementToEncrypt, RSA^ Alg, Strin // and use it to encrypt the XmlElement with the // a new random symmetric key. ////////////////////////////////////////////////// - // Create a 256 bit Rijndael key. - RijndaelManaged^ sessionKey = gcnew RijndaelManaged; + // Create a 256 bit Aes key. + Aes^ sessionKey = Aes::Create(); sessionKey->KeySize = 256; EncryptedXml^ eXml = gcnew EncryptedXml; array^encryptedElement = eXml->EncryptData( elementToEncrypt, sessionKey, false ); diff --git a/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/CPP/Cryptography.XML.XMLEncMapKey.cpp b/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/CPP/Cryptography.XML.XMLEncMapKey.cpp index 0c88aa89a44..a54ef5a3b1e 100644 --- a/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/CPP/Cryptography.XML.XMLEncMapKey.cpp +++ b/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/CPP/Cryptography.XML.XMLEncMapKey.cpp @@ -65,7 +65,7 @@ static void Encrypt( XmlDocument^ Doc, String^ ElementToEncrypt, SymmetricAlgori encryptionMethod = EncryptedXml::XmlEncDESUrl; } else - if ( dynamic_cast(Alg) ) + if ( dynamic_cast(Alg) ) { switch ( Alg->KeySize ) { diff --git a/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/CPP/Cryptography.XML.XMLEncMinimalDecryptData.cpp b/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/CPP/Cryptography.XML.XMLEncMinimalDecryptData.cpp index 81229454408..c5d86c84242 100644 --- a/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/CPP/Cryptography.XML.XMLEncMinimalDecryptData.cpp +++ b/samples/snippets/cpp/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/CPP/Cryptography.XML.XMLEncMinimalDecryptData.cpp @@ -65,7 +65,7 @@ static void Encrypt( XmlDocument^ Doc, String^ ElementToEncrypt, SymmetricAlgori encryptionMethod = EncryptedXml::XmlEncDESUrl; } else - if ( dynamic_cast(Alg) ) + if ( dynamic_cast(Alg) ) { switch ( Alg->KeySize ) { diff --git a/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CPP/source.cpp b/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CPP/source.cpp index 497b9be474a..f057ee25b8d 100644 --- a/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CPP/source.cpp +++ b/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CPP/source.cpp @@ -8,7 +8,7 @@ using namespace System::ComponentModel; using namespace System::Security::Cryptography; // -void EncryptData( String^ inName, String^ outName, array^rijnKey, array^rijnIV ) +void EncryptData( String^ inName, String^ outName, array^aesKey, array^aesIV ) { //Create the file streams to handle the input and output files. @@ -24,9 +24,9 @@ void EncryptData( String^ inName, String^ outName, array^rijnKey, arrayCreateEncryptor( rijnKey, rijnIV ),CryptoStreamMode::Write ); + CryptoStream^ encStream = gcnew CryptoStream( fout,aes->CreateEncryptor( aesKey, aesIV ),CryptoStreamMode::Write ); Console::WriteLine( "Encrypting..." ); //Read from the input file, then encrypt and write to the output file. diff --git a/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/CPP/members.cpp b/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/CPP/members.cpp index ae097c3616f..1da17eea7d3 100644 --- a/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/CPP/members.cpp +++ b/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/CPP/members.cpp @@ -27,19 +27,17 @@ namespace CryptographySample // Create a new symmetric algorithm and display its // key values. - SymmetricAlgorithm^ symAlg = - SymmetricAlgorithm::Create(); - ShowKeys(symAlg->LegalKeySizes, symAlg->ToString()); - Console::WriteLine("rijn.blocksize:{0}", - symAlg->BlockSize); + Aes^ aes = Aes::Create(); + ShowKeys(aes->LegalKeySizes, aes->ToString()); + Console::WriteLine("aes.blocksize:{0}", + aes->BlockSize); // Create a new RSA algorithm and display its key values. - RSACryptoServiceProvider^ rsaCSP = - gcnew RSACryptoServiceProvider(384); - ShowKeys(rsaCSP->LegalKeySizes, rsaCSP->ToString()); - Console::WriteLine("RSACryptoServiceProvider KeySize =" + RSA^ rsa = RSA::Create(); + ShowKeys(rsa->LegalKeySizes, rsa->ToString()); + Console::WriteLine("RSA KeySize =" " {0}", - rsaCSP->KeySize); + rsa->KeySize); Console::WriteLine("This sample completed successfully; " "press Enter to exit."); @@ -96,17 +94,17 @@ int main() // Interval between key size bits: 64 // // KeySizes retrieved from the -// System.Security.Cryptography.RijndaelManaged object. +// System.Security.Cryptography.Aes object. // Minimum key size bits: 128 // Maximum key size bits: 256 // Interval between key size bits: 64 -// rijn.blocksize:128 +// aes.blocksize:128 // // KeySizes retrieved from the -// System.Security.Cryptography.RSACryptoServiceProvider object. -// Minimum key size bits: 384 +// System.Security.Cryptography.RSA object. +// Minimum key size bits: 512 // Maximum key size bits: 16384 -// Interval between key size bits: 8 -// RSACryptoServiceProvider KeySize = 384 +// Interval between key size bits: 64 +// RSA KeySize = 2048 // This sample completed successfully; press Enter to exit. -// \ No newline at end of file +// diff --git a/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CPP/sample.cpp b/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CPP/sample.cpp index c598df28ecc..c258cb04496 100644 --- a/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CPP/sample.cpp +++ b/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CPP/sample.cpp @@ -32,7 +32,7 @@ int main() RSA->ImportParameters( RSAKeyInfo ); //Create a new instance of the Aes class. - Aes^ aes = gcnew Aes; + Aes^ aes = Aes::Create(); //Encrypt the symmetric key and IV. EncryptedSymmetricKey = RSA->Encrypt( aes->Key, false ); diff --git a/samples/snippets/csharp/VS_Snippets_CFX/s_ue_secureconversationservicecredential/cs/source.cs b/samples/snippets/csharp/VS_Snippets_CFX/s_ue_secureconversationservicecredential/cs/source.cs index cf4f1c8033c..53bbc163e70 100644 --- a/samples/snippets/csharp/VS_Snippets_CFX/s_ue_secureconversationservicecredential/cs/source.cs +++ b/samples/snippets/csharp/VS_Snippets_CFX/s_ue_secureconversationservicecredential/cs/source.cs @@ -76,9 +76,9 @@ static void Configure(ServiceHost serviceHost) } public class CertificateSecurityStateEncoder : SecurityStateEncoder { - RSACryptoServiceProvider rsaCryptoServiceProvider; + RSA rsa; CookieContainerSerializer serializer; - RijndaelManaged aesAlg; + Aes aesAlg; public CertificateSecurityStateEncoder(X509Certificate2 protectionCertificate) { @@ -92,16 +92,16 @@ public CertificateSecurityStateEncoder(X509Certificate2 protectionCertificate) throw new ArgumentException("protectionCertificate does not contain the private key which is required for performing encypt / decrypt operations."); } - rsaCryptoServiceProvider = protectionCertificate.PrivateKey as RSACryptoServiceProvider; - if (rsaCryptoServiceProvider == null) + rsa = protectionCertificate.GetRSAPrivateKey(); + if (rsa == null) { - throw new NotSupportedException("protectionCertificate must have a private key of type RSACryptoServiceProvider."); + throw new NotSupportedException("protectionCertificate must have a private key of type RSA."); } serializer = new CookieContainerSerializer(); // The symmetric key algorithm used to protect the cookie. - aesAlg = new RijndaelManaged(); + aesAlg = Aes.Create(); } protected override byte[] EncodeSecurityState(byte[] data) @@ -109,7 +109,7 @@ protected override byte[] EncodeSecurityState(byte[] data) // Create a new cookie container that will protect the WCF cookie. // Possible improvement: use a caching scheme so that a new cookie container // need not be created each time to improve performance. - CookieContainer cookieContainer = new CookieContainer(rsaCryptoServiceProvider, aesAlg); + CookieContainer cookieContainer = new CookieContainer(rsa, aesAlg); // Encrypt the cookie from WCF with our own scheme so that any of the backend services // can decrypt it. @@ -123,7 +123,7 @@ protected override byte[] DecodeSecurityState(byte[] data) { // Possible improvement: use a caching scheme so that a new cookie container // need not be created each time to improve performance. - CookieContainer cookieContainer = serializer.Deserialize(rsaCryptoServiceProvider, aesAlg, data); + CookieContainer cookieContainer = serializer.Deserialize(rsa, aesAlg, data); // Decrypt the cookie and return it to WCF so that WCF can use the cookie to // perform its own cryptographic operations. @@ -139,7 +139,7 @@ class CookieContainerSerializer /// The symmetric key algorithm to use to decrypt the cookie block. /// The byte array to deserialize. /// The deserialized cookie container instance. - public CookieContainer Deserialize(RSACryptoServiceProvider rsaKey, RijndaelManaged aesAlg, byte[] data) + public CookieContainer Deserialize(RSA rsaKey, Aes aesAlg, byte[] data) { CookieContainer cookieContainer = new CookieContainer(rsaKey, aesAlg); // Length of the IV according to the AES algorithm (in bytes). @@ -221,8 +221,8 @@ class CookieContainer byte[] encryptedCookie; ICryptoTransform encryptor; ICryptoTransform decryptor; - RijndaelManaged aesAlg; - RSACryptoServiceProvider protectionRsaKey; + Aes aesAlg; + RSA protectionRsaKey; /// /// Creates a new cookie container and auto-generate a symmetric key protected @@ -230,14 +230,14 @@ class CookieContainer /// /// The RSA key to protect the generated symmetric key. /// The symmetric key algorithm to use. - public CookieContainer(RSACryptoServiceProvider rsaKey, RijndaelManaged aesAlg) + public CookieContainer(RSA rsaKey, Aes aesAlg) { this.aesAlg = aesAlg; this.iv = aesAlg.IV; // Use the RSA key in the X509Certificate to protect the symmetric key. this.protectionRsaKey = rsaKey; - this.encryptedSymmetricKey = protectionRsaKey.Encrypt(aesAlg.Key, true); + this.encryptedSymmetricKey = protectionRsaKey.Encrypt(aesAlg.Key, RSAEncryptionPadding.OaepSHA1); // Create the enryptor and decryptor that will perform the actual // cryptographic operations. @@ -266,7 +266,7 @@ public void CreateCryptoTransformers() { // Only a service configured with the right X509 certificate // can decrypt the symmetric key. - byte[] symmetricKey = protectionRsaKey.Decrypt(encryptedSymmetricKey, true); + byte[] symmetricKey = protectionRsaKey.Decrypt(encryptedSymmetricKey, RSAEncryptionPadding.OaepSHA1); // Create an encryptor based on the symmetric key which can be used to encrypt SCT cookie blob. this.encryptor = aesAlg.CreateEncryptor(symmetricKey, iv); diff --git a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.DataReference/cs/sample.cs b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.DataReference/cs/sample.cs index 75696dd2139..6932bd5f02e 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.DataReference/cs/sample.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.DataReference/cs/sample.cs @@ -96,8 +96,8 @@ public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, string Encr // a new random symmetric key. ////////////////////////////////////////////////// - // Create a 256 bit Rijndael key. - RijndaelManaged sessionKey = new RijndaelManaged(); + // Create a 256 bit Aes key. + Aes sessionKey = Aes.Create(); sessionKey.KeySize = 256; EncryptedXml eXml = new EncryptedXml(); diff --git a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptedData/cs/sample.cs b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptedData/cs/sample.cs index e32b9801868..39636be7c7f 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptedData/cs/sample.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptedData/cs/sample.cs @@ -78,8 +78,8 @@ public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, RSA Alg, st // a new random symmetric key. ////////////////////////////////////////////////// - // Create a 256 bit Rijndael key. - RijndaelManaged sessionKey = new RijndaelManaged(); + // Create a 256 bit Aes key. + Aes sessionKey = Aes.Create(); sessionKey.KeySize = 256; EncryptedXml eXml = new EncryptedXml(); diff --git a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptedKey/cs/example.cs b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptedKey/cs/example.cs index 25d36925bc1..b4665591fb9 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptedKey/cs/example.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptedKey/cs/example.cs @@ -78,8 +78,8 @@ public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, RSA Alg, st // a new random symmetric key. ////////////////////////////////////////////////// - // Create a 256 bit Rijndael key. - RijndaelManaged sessionKey = new RijndaelManaged(); + // Create a 256 bit Aes key. + Aes sessionKey = Aes.Create(); sessionKey.KeySize = 256; EncryptedXml eXml = new EncryptedXml(); diff --git a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptionProperty/cs/sample.cs b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptionProperty/cs/sample.cs index 9e7934f549f..2f24d445613 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptionProperty/cs/sample.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.EncryptionProperty/cs/sample.cs @@ -78,8 +78,8 @@ public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, RSA Alg, st // a new random symmetric key. ////////////////////////////////////////////////// - // Create a 256 bit Rijndael key. - RijndaelManaged sessionKey = new RijndaelManaged(); + // Create a 256 bit Aes key. + Aes sessionKey = Aes.Create(); sessionKey.KeySize = 256; EncryptedXml eXml = new EncryptedXml(); diff --git a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/CS/sample.cs b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/CS/sample.cs index 288d0a2abd4..47a608fa547 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/CS/sample.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/CS/sample.cs @@ -89,8 +89,8 @@ public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, RSA Alg, st // a new random symmetric key. ////////////////////////////////////////////////// - // Create a 256 bit Rijndael key. - RijndaelManaged sessionKey = new RijndaelManaged(); + // Create a 256 bit Aes key. + Aes sessionKey = Aes.Create(); sessionKey.KeySize = 256; EncryptedXml eXml = new EncryptedXml(); diff --git a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/CS/sample.cs b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/CS/sample.cs index 16e239563fd..46928f2029b 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/CS/sample.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/CS/sample.cs @@ -113,7 +113,7 @@ public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, SymmetricAl { encryptionMethod = EncryptedXml.XmlEncDESUrl; } - else if (Alg is Rijndael) + else if (Alg is Aes) { switch (Alg.KeySize) { diff --git a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/CS/sample.cs b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/CS/sample.cs index 9f774310ed8..c61ced3ab7b 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/CS/sample.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/CS/sample.cs @@ -113,7 +113,7 @@ public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, SymmetricAl { encryptionMethod = EncryptedXml.XmlEncDESUrl; } - else if (Alg is Rijndael) + else if (Alg is Aes) { switch (Alg.KeySize) { diff --git a/samples/snippets/csharp/VS_Snippets_CLR/x509certificate2/cs/program.cs b/samples/snippets/csharp/VS_Snippets_CLR/x509certificate2/cs/program.cs index 1e0da74d9ac..ca95982ab70 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/x509certificate2/cs/program.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/x509certificate2/cs/program.cs @@ -39,10 +39,10 @@ static void Main(string[] args) } // Encrypt the file using the public key from the certificate. - EncryptFile(originalFile, (RSACryptoServiceProvider)cert.PublicKey.Key); + EncryptFile(originalFile, (RSA)cert.PublicKey.Key); // Decrypt the file using the private key from the certificate. - DecryptFile(encryptedFile, (RSACryptoServiceProvider)cert.PrivateKey); + DecryptFile(encryptedFile, cert.GetRSAPrivateKey()); //Display the original data and the decrypted data. Console.WriteLine("Original: {0}", File.ReadAllText(originalFile)); @@ -80,9 +80,9 @@ private static X509Certificate2 GetCertificateFromStore(string certName) // // Encrypt a file using a public key. - private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPublicKey) + private static void EncryptFile(string inFile, RSA rsaPublicKey) { - using (Aes aes = new Aes()) + using (Aes aes = Aes.Create()) { // Create instance of Aes for // symetric encryption of the data. @@ -133,7 +133,6 @@ private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPubli // a time, you can save memory // and accommodate large files. int count = 0; - int offset = 0; // blockSizeBytes can be any arbitrary size. int blockSizeBytes = aes.BlockSize / 8; @@ -144,8 +143,7 @@ private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPubli { do { - count = inFs.Read(data, offset, blockSizeBytes); - offset += count; + count = inFs.Read(data, 0, blockSizeBytes); outStreamEncrypted.Write(data, 0, count); bytesRead += count; } @@ -165,12 +163,12 @@ private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPubli // // Decrypt a file using a private key. - private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPrivateKey) + private static void DecryptFile(string inFile, RSA rsaPrivateKey) { // Create instance of Aes for // symetric decryption of the data. - using (Aes aes = new Aes()) + using (Aes aes = Aes.Create()) { aes.KeySize = 256; aes.Mode = CipherMode.CBC; @@ -221,9 +219,9 @@ private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPriva inFs.Read(IV, 0, lenIV); Directory.CreateDirectory(decrFolder); // - // Use RSACryptoServiceProvider + // Use RSA // to decrypt the Aes key. - byte[] KeyDecrypted = rsaPrivateKey.Decrypt(KeyEncrypted, false); + byte[] KeyDecrypted = rsaPrivateKey.Decrypt(KeyEncrypted, RSAEncryptionPadding.Pkcs1); // Decrypt the key. using (ICryptoTransform transform = aes.CreateDecryptor(KeyDecrypted, IV)) @@ -238,7 +236,6 @@ private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPriva { int count = 0; - int offset = 0; int blockSizeBytes = aes.BlockSize / 8; byte[] data = new byte[blockSizeBytes]; @@ -254,8 +251,7 @@ private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPriva { do { - count = inFs.Read(data, offset, blockSizeBytes); - offset += count; + count = inFs.Read(data, 0, blockSizeBytes); outStreamDecrypted.Write(data, 0, count); } while (count > 0); diff --git a/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CS/source.cs b/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CS/source.cs index cb54c7e43af..0c817899ea8 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CS/source.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CS/source.cs @@ -6,7 +6,7 @@ public class Sample { // -private static void EncryptData(String inName, String outName, byte[] rijnKey, byte[] rijnIV) +private static void EncryptData(String inName, String outName, byte[] aesKey, byte[] aesIV) { //Create the file streams to handle the input and output files. FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read); @@ -19,8 +19,8 @@ private static void EncryptData(String inName, String outName, byte[] rijnKey, b long totlen = fin.Length; //This is the total length of the input file. int len; //This is the number of bytes to be written at a time. - SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); //Creates the default implementation, which is RijndaelManaged. - CryptoStream encStream = new CryptoStream(fout, rijn.CreateEncryptor(rijnKey, rijnIV), CryptoStreamMode.Write); + Aes aes = Aes.Create(); + CryptoStream encStream = new CryptoStream(fout, aes.CreateEncryptor(aesKey, aesIV), CryptoStreamMode.Write); Console.WriteLine("Encrypting..."); diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/CS/members.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/CS/members.cs index 501c83a91d5..41d987912d3 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/CS/members.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/CS/members.cs @@ -23,16 +23,15 @@ static void Main(string[] args) ShowKeys(new KeySizes[1]{keySizes}, "Custom Keys"); // Create a new symmetric algorithm and display its key values. - SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); - ShowKeys(rijn.LegalKeySizes, rijn.ToString()); - Console.WriteLine("rijn.blocksize:" + rijn.BlockSize); + Aes aes = Aes.Create(); + ShowKeys(aes.LegalKeySizes, aes.ToString()); + Console.WriteLine("aes.blocksize:" + aes.BlockSize); // Create a new RSA algorithm and display its key values. - RSACryptoServiceProvider rsaCSP = - new RSACryptoServiceProvider(384); - ShowKeys(rsaCSP.LegalKeySizes, rsaCSP.ToString()); - Console.WriteLine("RSACryptoServiceProvider KeySize = " + - rsaCSP.KeySize); + RSA rsa = RSA.Create(); + ShowKeys(rsa.LegalKeySizes, rsa.ToString()); + Console.WriteLine("RSA KeySize = " + + rsa.KeySize); Console.WriteLine("This sample completed successfully; " + "press Enter to exit."); @@ -77,18 +76,18 @@ private static void ShowKeys(KeySizes[] keySizes, string objectName) // Maximum key size bits: 1024 // Interval between key size bits: 64 // -// KeySizes retrieved from the System.Security.Cryptography.RijndaelManaged +// KeySizes retrieved from the System.Security.Cryptography.Aes // object. // Minimum key size bits: 128 // Maximum key size bits: 256 // Interval between key size bits: 64 -// rijn.blocksize:128 +// aes.blocksize:128 // // KeySizes retrieved from the -// System.Security.Cryptography.RSACryptoServiceProvider object. -// Minimum key size bits: 384 +// System.Security.Cryptography.RSA object. +// Minimum key size bits: 512 // Maximum key size bits: 16384 -// Interval between key size bits: 8 -// RSACryptoServiceProvider KeySize = 384 +// Interval between key size bits: 64 +// RSA KeySize = 2048 // This sample completed successfully; press Enter to exit. -// \ No newline at end of file +// diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CS/sample.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CS/sample.cs index 75e3d2a4fa7..5a61d5c39b3 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CS/sample.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CS/sample.cs @@ -38,7 +38,7 @@ static void Main() RSA.ImportParameters(RSAKeyInfo); //Create a new instance of the Aes class. - Aes aes = new Aes(); + Aes aes = Aes.Create(); //Encrypt the symmetric key and IV. EncryptedSymmetricKey = RSA.Encrypt(aes.Key, false); @@ -54,4 +54,4 @@ static void Main() } } } -// \ No newline at end of file +// diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.Xml.Keyreference/cs/sample.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.Xml.Keyreference/cs/sample.cs index 52a83b21389..83bc3a95ad7 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.Xml.Keyreference/cs/sample.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.Xml.Keyreference/cs/sample.cs @@ -96,8 +96,8 @@ public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, string Encr // a new random symmetric key. ////////////////////////////////////////////////// - // Create a 256 bit Rijndael key. - RijndaelManaged sessionKey = new RijndaelManaged(); + // Create a 256 bit Aes key. + Aes sessionKey = Aes.Create(); sessionKey.KeySize = 256; EncryptedXml eXml = new EncryptedXml(); diff --git a/samples/snippets/csharp/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/cs/program.cs b/samples/snippets/csharp/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/cs/program.cs index b4b22821638..8b983b34fa9 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/cs/program.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/cs/program.cs @@ -7,8 +7,8 @@ class Program { static void Main(string[] args) { - AesManaged aes = new AesManaged(); - Console.WriteLine("AesManaged "); + Aes aes = Aes.Create(); + Console.WriteLine("Aes "); KeySizes[] ks = aes.LegalKeySizes; foreach (KeySizes k in ks) { @@ -21,116 +21,20 @@ static void Main(string[] args) Console.WriteLine("\tLegal min block size = " + k.MinSize); Console.WriteLine("\tLegal max block size = " + k.MaxSize); } - DESCryptoServiceProvider des = new DESCryptoServiceProvider(); - Console.WriteLine("DESCryptoServiceProvider "); - ks = des.LegalKeySizes; - foreach (KeySizes k in ks) - { - Console.WriteLine("\tLegal min key size = " + k.MinSize); - Console.WriteLine("\tLegal max key size = " + k.MaxSize); - } - ks = des.LegalBlockSizes; - foreach (KeySizes k in ks) - { - Console.WriteLine("\tLegal min block size = " + k.MinSize); - Console.WriteLine("\tLegal max block size = " + k.MaxSize); - } - RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider(); - Console.WriteLine("RC2CryptoServiceProvider "); - ks = rc2.LegalKeySizes; - foreach (KeySizes k in ks) - { - Console.WriteLine("\tLegal min key size = " + k.MinSize); - Console.WriteLine("\tLegal max key size = " + k.MaxSize); - } - ks = rc2.LegalBlockSizes; - foreach (KeySizes k in ks) - { - Console.WriteLine("\tLegal min block size = " + k.MinSize); - Console.WriteLine("\tLegal max block size = " + k.MaxSize); - } - RijndaelManaged rij = new RijndaelManaged(); - Console.WriteLine("RijndaelManaged "); - ks = rij.LegalKeySizes; - foreach (KeySizes k in ks) - { - Console.WriteLine("\tLegal min key size = " + k.MinSize); - Console.WriteLine("\tLegal max key size = " + k.MaxSize); - } - ks = rij.LegalBlockSizes; - foreach (KeySizes k in ks) - { - Console.WriteLine("\tLegal min block size = " + k.MinSize); - Console.WriteLine("\tLegal max block size = " + k.MaxSize); - } - TripleDESCryptoServiceProvider tsp = new TripleDESCryptoServiceProvider(); - Console.WriteLine("TripleDESCryptoServiceProvider "); - ks = tsp.LegalKeySizes; - foreach (KeySizes k in ks) - { - Console.WriteLine("\tLegal min key size = " + k.MinSize); - Console.WriteLine("\tLegal max key size = " + k.MaxSize); - } - ks = tsp.LegalBlockSizes; - foreach (KeySizes k in ks) - { - Console.WriteLine("\tLegal min block size = " + k.MinSize); - Console.WriteLine("\tLegal max block size = " + k.MaxSize); - } } } } //This sample produces the following output when run on .NET Framework: -//AesManaged +//Aes // Legal min key size = 128 // Legal max key size = 256 // Legal min block size = 128 // Legal max block size = 128 -//DESCryptoServiceProvider -// Legal min key size = 64 -// Legal max key size = 64 -// Legal min block size = 64 -// Legal max block size = 64 -//RC2CryptoServiceProvider -// Legal min key size = 40 -// Legal max key size = 128 -// Legal min block size = 64 -// Legal max block size = 64 -//RijndaelManaged -// Legal min key size = 128 -// Legal max key size = 256 -// Legal min block size = 128 -// Legal max block size = 256 -//TripleDESCryptoServiceProvider -// Legal min key size = 128 -// Legal max key size = 192 -// Legal min block size = 64 -// Legal max block size = 64 // //This sample produces the following output when run on .NET Core: -//AesManaged -// Legal min key size = 128 -// Legal max key size = 256 -// Legal min block size = 128 -// Legal max block size = 128 -//DESCryptoServiceProvider -// Legal min key size = 64 -// Legal max key size = 64 -// Legal min block size = 64 -// Legal max block size = 64 -//RC2CryptoServiceProvider -// Legal min key size = 40 -// Legal max key size = 128 -// Legal min block size = 64 -// Legal max block size = 64 -//RijndaelManaged +//Aes // Legal min key size = 128 // Legal max key size = 256 // Legal min block size = 128 // Legal max block size = 128 -//TripleDESCryptoServiceProvider -// Legal min key size = 128 -// Legal max key size = 192 -// Legal min block size = 64 -// Legal max block size = 64 // diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.DataReference/vb/sample.vb b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.DataReference/vb/sample.vb index 569c2e6e6a4..66275d6eb87 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.DataReference/vb/sample.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.DataReference/vb/sample.vb @@ -96,8 +96,8 @@ Module XMLEncryptionSubs ' a new random symmetric key. '''''''''''''''''''''''''''''''''''''''''''''''' - ' Create a 256 bit Rijndael key. - Dim sessionKey As New RijndaelManaged() + ' Create a 256 bit Aes key. + Dim sessionKey As Aes = Aes.Create() sessionKey.KeySize = 256 Dim eXml As New EncryptedXml() diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptedData/vb/sample.vb b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptedData/vb/sample.vb index b665a162254..bd3a99d0a86 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptedData/vb/sample.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptedData/vb/sample.vb @@ -73,8 +73,8 @@ Module Program ' and use it to encrypt the XmlElement with the ' a new random symmetric key. '''''''''''''''''''''''''''''''''''''''''''''''' - ' Create a 256 bit Rijndael key. - Dim sessionKey As New RijndaelManaged() + ' Create a 256 bit Aes key. + Dim sessionKey As Aes = Aes.Create() sessionKey.KeySize = 256 Dim eXml As New EncryptedXml() diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptedKey/vb/example.vb b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptedKey/vb/example.vb index cfbe61dcc14..5df1840b7dc 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptedKey/vb/example.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptedKey/vb/example.vb @@ -73,8 +73,8 @@ Module Program ' and use it to encrypt the XmlElement with the ' a new random symmetric key. '''''''''''''''''''''''''''''''''''''''''''''''''''' - ' Create a 256 bit Rijndael key. - Dim sessionKey As New RijndaelManaged() + ' Create a 256 bit Aes key. + Dim sessionKey As Aes = Aes.Create() sessionKey.KeySize = 256 Dim eXml As New EncryptedXml() diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptionProperty/vb/sample.vb b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptionProperty/vb/sample.vb index bb5bfd76664..7c2b3af0bea 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptionProperty/vb/sample.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.EncryptionProperty/vb/sample.vb @@ -22,7 +22,7 @@ Module Program ' Create a new RSA key. This key will encrypt a symmetric key, ' which will then be imbedded in the XML document. - Dim rsaKey As New RSACryptoServiceProvider() + Dim rsaKey As RSA = RSA.Create() Try @@ -72,8 +72,8 @@ Module Program ' and use it to encrypt the XmlElement with the ' a new random symmetric key. '''''''''''''''''''''''''''''''''''''''''''''''''' - ' Create a 256 bit Rijndael key. - Dim sessionKey As New RijndaelManaged() + ' Create a 256 bit Aes key. + Dim sessionKey As Aes = Aes.Create() sessionKey.KeySize = 256 Dim eXml As New EncryptedXml() diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/VB/sample.vb b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/VB/sample.vb index 6ad0f7a8f52..9ed48e14907 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/VB/sample.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncImbedKey/VB/sample.vb @@ -82,8 +82,8 @@ Module Program ' and use it to encrypt the XmlElement with the ' a new random symmetric key. ''''''''''''''''''''''''''''''''''''''''''''''''''' - ' Create a 256 bit Rijndael key. - Dim sessionKey As New RijndaelManaged() + ' Create a 256 bit Aes key. + Dim sessionKey As Aes = Aes.Create() sessionKey.KeySize = 256 Dim eXml As New EncryptedXml() diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/VB/sample.vb b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/VB/sample.vb index 8a6fd229d71..f95dde55ec7 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/VB/sample.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncMapKey/VB/sample.vb @@ -102,7 +102,7 @@ Module Program encryptionMethod = EncryptedXml.XmlEncTripleDESUrl ElseIf TypeOf Alg Is DES Then encryptionMethod = EncryptedXml.XmlEncDESUrl - ElseIf TypeOf Alg Is Rijndael Then + ElseIf TypeOf Alg Is Aes Then Select Case Alg.KeySize Case 128 encryptionMethod = EncryptedXml.XmlEncAES128Url diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/VB/sample.vb b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/VB/sample.vb index a82f9951613..3719ba2e291 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/VB/sample.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR/Cryptography.XML.XMLEncMinimalDecryptData/VB/sample.vb @@ -102,7 +102,7 @@ Module Program encryptionMethod = EncryptedXml.XmlEncTripleDESUrl ElseIf TypeOf Alg Is DES Then encryptionMethod = EncryptedXml.XmlEncDESUrl - ElseIf TypeOf Alg Is Rijndael Then + ElseIf TypeOf Alg Is Aes Then Select Case Alg.KeySize Case 128 encryptionMethod = EncryptedXml.XmlEncAES128Url diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR/x509certificate2/vb/program.vb b/samples/snippets/visualbasic/VS_Snippets_CLR/x509certificate2/vb/program.vb index 72d56bfa595..d22e2000723 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR/x509certificate2/vb/program.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR/x509certificate2/vb/program.vb @@ -1,4 +1,4 @@ -' +' Imports System.Security.Cryptography Imports System.Security.Cryptography.X509Certificates Imports System.IO @@ -36,10 +36,10 @@ Class Program ' Encrypt the file using the public key from the certificate. - EncryptFile(originalFile, CType(cert.PublicKey.Key, RSACryptoServiceProvider)) + EncryptFile(originalFile, CType(cert.PublicKey.Key, RSA)) ' Decrypt the file using the private key from the certificate. - DecryptFile(encryptedFile, CType(cert.PrivateKey, RSACryptoServiceProvider)) + DecryptFile(encryptedFile, cert.GetRSAPrivateKey()) 'Display the original data and the decrypted data. Console.WriteLine("Original: {0}", File.ReadAllText(originalFile)) @@ -76,8 +76,8 @@ Class Program ' ' ' Encrypt a file using a public key. - Private Shared Sub EncryptFile(ByVal inFile As String, ByVal rsaPublicKey As RSACryptoServiceProvider) - Dim aes As New Aes() + Private Shared Sub EncryptFile(ByVal inFile As String, ByVal rsaPublicKey As RSA) + Dim aes As Aes = Aes.Create() Try ' Create instance of Aes for ' symetric encryption of the data. @@ -95,7 +95,7 @@ Class Program Dim lKey As Integer = keyEncrypted.Length LenK = BitConverter.GetBytes(lKey) - Dim lIV As Integer = aesM.IV.Length + Dim lIV As Integer = aes.IV.Length LenIV = BitConverter.GetBytes(lIV) ' Write the following to the FileStream @@ -127,7 +127,6 @@ Class Program ' a time, you can save memory ' and accommodate large files. Dim count As Integer = 0 - Dim offset As Integer = 0 ' blockSizeBytes can be any arbitrary size. Dim blockSizeBytes As Integer = aes.BlockSize / 8 @@ -137,8 +136,7 @@ Class Program Dim inFs As New FileStream(inFile, FileMode.Open) Try Do - count = inFs.Read(data, offset, blockSizeBytes) - offset += count + count = inFs.Read(data, 0, blockSizeBytes) outStreamEncrypted.Write(data, 0, count) bytesRead += count Loop While count > 0 @@ -168,11 +166,11 @@ Class Program ' ' ' Decrypt a file using a private key. - Private Shared Sub DecryptFile(ByVal inFile As String, ByVal rsaPrivateKey As RSACryptoServiceProvider) + Private Shared Sub DecryptFile(ByVal inFile As String, ByVal rsaPrivateKey As RSA) ' Create instance of Aes for ' symetric decryption of the data. - Dim aes As New Aes() + Dim aes As Aes = Aes.Create() Try aes.KeySize = 256 aes.Mode = CipherMode.CBC @@ -203,7 +201,7 @@ Class Program Dim lengthIV As Integer = BitConverter.ToInt32(LenIV, 0) ' Determine the start postition of - ' the ciphter text (startC) + ' the cipher text (startC) ' and its length(lenC). Dim startC As Integer = lengthK + lengthIV + 8 Dim lenC As Integer = (CType(inFs.Length, Integer) - startC) @@ -223,9 +221,9 @@ Class Program inFs.Read(IV, 0, lengthIV) Directory.CreateDirectory(decrFolder) ' - ' Use RSACryptoServiceProvider + ' Use RSA ' to decrypt the AES key. - Dim KeyDecrypted As Byte() = rsaPrivateKey.Decrypt(KeyEncrypted, False) + Dim KeyDecrypted As Byte() = rsaPrivateKey.Decrypt(KeyEncrypted, RSAEncryptionPadding.Pkcs1) ' Decrypt the key. Dim transform As ICryptoTransform = aes.CreateDecryptor(KeyDecrypted, IV) @@ -242,7 +240,6 @@ Class Program ' for the decrypted file (outFs). Dim count As Integer = 0 - Dim offset As Integer = 0 Dim blockSizeBytes As Integer = aes.BlockSize / 8 Dim data(blockSizeBytes) As Byte @@ -256,8 +253,7 @@ Class Program Dim outStreamDecrypted As New CryptoStream(outFs, transform, CryptoStreamMode.Write) Try Do - count = inFs.Read(data, offset, blockSizeBytes) - offset += count + count = inFs.Read(data, 0, blockSizeBytes) outStreamDecrypted.Write(data, 0, count) Loop While count > 0 diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/VB/members.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/VB/members.vb index 636f12ec8f4..94a7bc98a75 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/VB/members.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.KeySizes/VB/members.vb @@ -26,15 +26,15 @@ Public Class Form1 ShowKeys(New KeySizes(0) {keySizes}, "Custom Keys") ' Create a new symmetric algorithm and display its key values. - Dim rijn As SymmetricAlgorithm = SymmetricAlgorithm.Create() - WriteLine("rijn.blocksize:" + rijn.BlockSize.ToString()) - ShowKeys(rijn.LegalKeySizes, rijn.ToString()) + Dim aes As Aes = Aes.Create() + WriteLine("aes.blocksize:" + aes.BlockSize.ToString()) + ShowKeys(aes.LegalKeySizes, aes.ToString()) ' Create a new RSA algorithm and display its key values. - Dim rsaCSP As New RSACryptoServiceProvider(384) - WriteLine("RSACryptoServiceProvider KeySize = " + _ - rsaCSP.KeySize.ToString()) - ShowKeys(rsaCSP.LegalKeySizes, rsaCSP.ToString()) + Dim rsa As RSA = RSA.Create() + WriteLine("RSA KeySize = " + _ + rsa.KeySize.ToString()) + ShowKeys(rsa.LegalKeySizes, rsa.ToString()) ' Reset the cursor and conclude application. WriteLine("This sample completed successfully;" + _ @@ -211,19 +211,19 @@ End Class ' Maximum key size bits: 1024 ' Interval between key size bits: 64 ' -' rijn.blocksize:128 -' KeySizes retrieved from the System.Security.Cryptography.RijndaelManaged +' aes.blocksize:128 +' KeySizes retrieved from the System.Security.Cryptography.Aes ' object. ' Minimum key size bits: 128 ' Maximum key size bits: 256 ' Interval between key size bits: 64 ' -' RSACryptoServiceProvider KeySize = 384 +' RSA KeySize = 2048 ' KeySizes retrieved from the -' System.Security.Cryptography.RSACryptoServiceProvider object. -' Minimum key size bits: 384 +' System.Security.Cryptography.RSA object. +' Minimum key size bits: 512 ' Maximum key size bits: 16384 -' Interval between key size bits: 8 +' Interval between key size bits: 64 ' ' This sample completed successfully; press Exit to continue. -' \ No newline at end of file +' diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/VB/sample.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/VB/sample.vb index 62b22ef77c7..fa398c11f19 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/VB/sample.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/VB/sample.vb @@ -28,13 +28,13 @@ Class RSACSPSample RSA.ImportParameters(RSAKeyInfo) 'Create a new instance of the Aes class. - Dim aes As New Aes() + Dim aes As Aes = Aes.Create() 'Encrypt the symmetric key and IV. EncryptedSymmetricKey = RSA.Encrypt(aes.Key, False) EncryptedSymmetricIV = RSA.Encrypt(aes.IV, False) - Console.WriteLine("Aes Key and IV have been encrypted with RSACryptoServiceProvider.") + Console.WriteLine("Aes Key and IV have been encrypted with RSA.") 'Catch and display a CryptographicException 'to the console. diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.Xml.Keyreference/vb/sample.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.Xml.Keyreference/vb/sample.vb index 93931187814..2d434f0fa48 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.Xml.Keyreference/vb/sample.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Security.Cryptography.Xml.Keyreference/vb/sample.vb @@ -96,8 +96,8 @@ Module XMLEncryptionSubs ' a new random symmetric key. '''''''''''''''''''''''''''''''''''''''''''''''' - ' Create a 256 bit Rijndael key. - Dim sessionKey As New RijndaelManaged() + ' Create a 256 bit Aes key. + Dim sessionKey As Aes = Aes.Create() sessionKey.KeySize = 256 Dim eXml As New EncryptedXml() diff --git a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/vb/program.vb b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/vb/program.vb index 0ad8012e4c0..a23132805ab 100644 --- a/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/vb/program.vb +++ b/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/vb/program.vb @@ -5,80 +5,21 @@ Imports System.Security.Cryptography Class Program Shared Sub Main(ByVal args() As String) - Dim aes As New AesManaged() - Console.WriteLine("AesManaged ") + Dim aes As Aes = Aes.Create() + Console.WriteLine("Aes ") Dim ks As KeySizes() = aes.LegalKeySizes Dim k As KeySizes For Each k In ks - Console.WriteLine(vbTab + "Legal min key size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max key size = " + k.MaxSize) + Console.WriteLine(vbTab + "Legal min key size = " & k.MinSize) + Console.WriteLine(vbTab + "Legal max key size = " & k.MaxSize) Next k ks = aes.LegalBlockSizes For Each k In ks - Console.WriteLine(vbTab + "Legal min block size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max block size = " + k.MaxSize) + Console.WriteLine(vbTab + "Legal min block size = " & k.MinSize) + Console.WriteLine(vbTab + "Legal max block size = " & k.MaxSize) Next k - Dim des As New DESCryptoServiceProvider() - Console.WriteLine("DESCryptoServiceProvider ") - ks = des.LegalKeySizes - - For Each k In ks - Console.WriteLine(vbTab + "Legal min key size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max key size = " + k.MaxSize) - Next k - ks = des.LegalBlockSizes - - For Each k In ks - Console.WriteLine(vbTab + "Legal min block size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max block size = " + k.MaxSize) - Next k - - Dim rc2 As New RC2CryptoServiceProvider() - Console.WriteLine("RC2CryptoServiceProvider ") - ks = rc2.LegalKeySizes - - For Each k In ks - Console.WriteLine(vbTab + "Legal min key size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max key size = " + k.MaxSize) - Next k - ks = rc2.LegalBlockSizes - - For Each k In ks - Console.WriteLine(vbTab + "Legal min block size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max block size = " + k.MaxSize) - Next k - - Dim rij As New RijndaelManaged() - Console.WriteLine("RijndaelManaged ") - ks = rij.LegalKeySizes - - For Each k In ks - Console.WriteLine(vbTab + "Legal min key size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max key size = " + k.MaxSize) - Next k - ks = rij.LegalBlockSizes - - For Each k In ks - Console.WriteLine(vbTab + "Legal min block size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max block size = " + k.MaxSize) - Next k - - Dim tsp As New TripleDESCryptoServiceProvider() - Console.WriteLine("TripleDESCryptoServiceProvider ") - ks = tsp.LegalKeySizes - - For Each k In ks - Console.WriteLine(vbTab + "Legal min key size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max key size = " + k.MaxSize) - Next k - ks = tsp.LegalBlockSizes - - For Each k In ks - Console.WriteLine(vbTab + "Legal min block size = " + k.MinSize) - Console.WriteLine(vbTab + "Legal max block size = " + k.MaxSize) - Next k End Sub End Class @@ -88,26 +29,6 @@ End Class ' Legal max key size = 256 ' Legal min block size = 128 ' Legal max block size = 128 -'DESCryptoServiceProvider -' Legal min key size = 64 -' Legal max key size = 64 -' Legal min block size = 64 -' Legal max block size = 64 -'RC2CryptoServiceProvider -' Legal min key size = 40 -' Legal max key size = 128 -' Legal min block size = 64 -' Legal max block size = 64 -'RijndaelManaged -' Legal min key size = 128 -' Legal max key size = 256 -' Legal min block size = 128 -' Legal max block size = 256 -'TripleDESCryptoServiceProvider -' Legal min key size = 128 -' Legal max key size = 192 -' Legal min block size = 64 -' Legal max block size = 64 ' 'This sample produces the following output when run on .NET Core: 'AesManaged @@ -115,24 +36,4 @@ End Class ' Legal max key size = 256 ' Legal min block size = 128 ' Legal max block size = 128 -'DESCryptoServiceProvider -' Legal min key size = 64 -' Legal max key size = 64 -' Legal min block size = 64 -' Legal max block size = 64 -'RC2CryptoServiceProvider -' Legal min key size = 40 -' Legal max key size = 128 -' Legal min block size = 64 -' Legal max block size = 64 -'RijndaelManaged -' Legal min key size = 128 -' Legal max key size = 256 -' Legal min block size = 128 -' Legal max block size = 128 -'TripleDESCryptoServiceProvider -' Legal min key size = 128 -' Legal max key size = 192 -' Legal min block size = 64 -' Legal max block size = 64 ' \ No newline at end of file diff --git a/xml/System.Security.Cryptography/RSACryptoServiceProvider.xml b/xml/System.Security.Cryptography/RSACryptoServiceProvider.xml index e7d53af56f9..f39acfefa6a 100644 --- a/xml/System.Security.Cryptography/RSACryptoServiceProvider.xml +++ b/xml/System.Security.Cryptography/RSACryptoServiceProvider.xml @@ -732,7 +732,7 @@ If no key is loaded via the object to the value of a public key (sent by another party), generates a session key using the algorithm, and then encrypts the session key using the object. Using this scheme, the session key could be sent back to the owner of the private RSA key and the two parties could use the session key to exchange encrypted data. + The following code example initializes an object to the value of a public key (sent by another party), generates a session key using the algorithm, and then encrypts the session key using the object. Using this scheme, the session key could be sent back to the owner of the private RSA key and the two parties could use the session key to exchange encrypted data. [!code-cpp[System.Security.Cryptography.RSACryptoServiceProvider.Encrypt#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CPP/sample.cpp#1)] [!code-csharp[System.Security.Cryptography.RSACryptoServiceProvider.Encrypt#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CS/sample.cs#1)] diff --git a/xml/System.Security.Cryptography/SymmetricAlgorithm.xml b/xml/System.Security.Cryptography/SymmetricAlgorithm.xml index e25faddcfcc..64e2dc51520 100644 --- a/xml/System.Security.Cryptography/SymmetricAlgorithm.xml +++ b/xml/System.Security.Cryptography/SymmetricAlgorithm.xml @@ -49,7 +49,7 @@ ## Remarks The classes that derive from the class use a chaining mode called cipher block chaining (CBC), which requires a key () and an initialization vector () to perform cryptographic transformations on data. To decrypt data that was encrypted using one of the classes, you must set the property and the property to the same values that were used for encryption. For a symmetric algorithm to be useful, the secret key must be known only to the sender and the receiver. - , , , and are implementations of symmetric algorithms. + , , , and are implementations of symmetric algorithms. Note that when using derived classes, it is not enough, from a security perspective, to simply force a garbage collection after you have finished using the object. You must explicitly call the method on the object to zero out any sensitive data within the object before it is released. Note that garbage collection does not zero out the contents of collected objects but simply marks the memory as available for reallocation. Thus the data contained within a garbage collected object may still be present in the memory heap in unallocated memory. In the case of cryptographic objects, this data could contain sensitive information such as key data or a block of plain text. @@ -58,7 +58,7 @@ ## Examples - The following code example uses the class with the specified property and initialization vector () to encrypt a file specified by `inName`, and outputs the encrypted result to the file specified by `outName`. The `desKey` and `desIV` parameters to the method are 8-byte arrays. You must have the high encryption pack installed to run this example. + The following code example uses the class with the specified property and initialization vector () to encrypt a file specified by `inName`, and outputs the encrypted result to the file specified by `outName`. The `desKey` and `desIV` parameters to the method are 8-byte arrays. You must have the high encryption pack installed to run this example. [!code-cpp[Classic CryptoStream Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CPP/source.cpp#1)] [!code-csharp[Classic CryptoStream Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CS/source.cs#1)] @@ -308,12 +308,9 @@ class with the specified property and initialization vector () to encrypt a file specified by `inName`, and outputs the encrypted result to the file specified by `outName`. The `desKey` and `desIV` parameters to the method are 8-byte arrays. You must have the high encryption pack installed to run this example. - - [!code-cpp[Classic CryptoStream Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CPP/source.cpp#1)] - [!code-csharp[Classic CryptoStream Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic CryptoStream Example/CS/source.cs#1)] - [!code-vb[Classic CryptoStream Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic CryptoStream Example/VB/source.vb#1)] +## Remarks + +We recommend that you specify the algorithm to use. See the overload of this method. ]]> @@ -1353,7 +1350,7 @@ Allows an to attempt to free resources and perfor ## Examples - The following example shows the value of for the symmetric algorithms. + The following example shows the value of for the AES symmetric algorithm. [!code-csharp[System.Security.Cryptography.SymmetricAlgorithm.BlockSize#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/cs/program.cs#1)] [!code-vb[System.Security.Cryptography.SymmetricAlgorithm.BlockSize#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.security.cryptography.symmetricalgorithm.blocksize/vb/program.vb#1)] diff --git a/xml/System.Web.Configuration/MachineKeyValidation.xml b/xml/System.Web.Configuration/MachineKeyValidation.xml index 81057ab61b1..79cbbaf69ee 100644 --- a/xml/System.Web.Configuration/MachineKeyValidation.xml +++ b/xml/System.Web.Configuration/MachineKeyValidation.xml @@ -58,7 +58,7 @@ 3 - Specifies that ASP.NET uses the (Rijndael) encryption algorithm. Choose this option if you want to encrypt view state in your Web application. + Specifies that ASP.NET uses the encryption algorithm. Choose this option if you want to encrypt view state in your Web application. If you choose this option, the property will be used for encryption and decryption, and the hash algorithm will be used with the property for validation.