diff --git a/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/CPP/fileexample.cpp b/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/CPP/fileexample.cpp deleted file mode 100644 index 3a2a66eed8a..00000000000 --- a/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/CPP/fileexample.cpp +++ /dev/null @@ -1,113 +0,0 @@ - -// -using namespace System; -using namespace System::Security::Cryptography; -using namespace System::Text; -using namespace System::IO; -void EncryptTextToFile( String^ Data, String^ FileName, array^Key, array^IV ) -{ - try - { - - // Create or open the specified file. - FileStream^ fStream = File::Open( FileName, FileMode::OpenOrCreate ); - - // Create a CryptoStream using the FileStream - // and the passed key and initialization vector (IV). - CryptoStream^ cStream = gcnew CryptoStream( fStream,(gcnew TripleDESCryptoServiceProvider)->CreateEncryptor( Key, IV ),CryptoStreamMode::Write ); - - // Create a StreamWriter using the CryptoStream. - StreamWriter^ sWriter = gcnew StreamWriter( cStream ); - - // Write the data to the stream - // to encrypt it. - sWriter->WriteLine( Data ); - - // Close the streams and - // close the file. - sWriter->Close(); - cStream->Close(); - fStream->Close(); - } - catch ( CryptographicException^ e ) - { - Console::WriteLine( "A Cryptographic error occurred: {0}", e->Message ); - } - catch ( UnauthorizedAccessException^ e ) - { - Console::WriteLine( "A file access error occurred: {0}", e->Message ); - } - -} - -String^ DecryptTextFromFile( String^ FileName, array^Key, array^IV ) -{ - try - { - - // Create or open the specified file. - FileStream^ fStream = File::Open( FileName, FileMode::OpenOrCreate ); - - // Create a CryptoStream using the FileStream - // and the passed key and initialization vector (IV). - CryptoStream^ cStream = gcnew CryptoStream( fStream,(gcnew TripleDESCryptoServiceProvider)->CreateDecryptor( Key, IV ),CryptoStreamMode::Read ); - - // Create a StreamReader using the CryptoStream. - StreamReader^ sReader = gcnew StreamReader( cStream ); - - // Read the data from the stream - // to decrypt it. - String^ val = sReader->ReadLine(); - - // Close the streams and - // close the file. - sReader->Close(); - cStream->Close(); - fStream->Close(); - - // Return the string. - return val; - } - catch ( CryptographicException^ e ) - { - Console::WriteLine( "A Cryptographic error occurred: {0}", e->Message ); - return nullptr; - } - catch ( UnauthorizedAccessException^ e ) - { - Console::WriteLine( "A file access error occurred: {0}", e->Message ); - return nullptr; - } - -} - -int main() -{ - try - { - - // Create a new TripleDESCryptoServiceProvider object - // to generate a key and initialization vector (IV). - TripleDESCryptoServiceProvider^ tDESalg = gcnew TripleDESCryptoServiceProvider; - - // Create a string to encrypt. - String^ sData = "Here is some data to encrypt."; - String^ FileName = "CText.txt"; - - // Encrypt text to a file using the file name, key, and IV. - EncryptTextToFile( sData, FileName, tDESalg->Key, tDESalg->IV ); - - // Decrypt the text from a file using the file name, key, and IV. - String^ Final = DecryptTextFromFile( FileName, tDESalg->Key, tDESalg->IV ); - - // Display the decrypted string to the console. - Console::WriteLine( Final ); - } - catch ( Exception^ e ) - { - Console::WriteLine( e->Message ); - } - -} - -// diff --git a/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/CPP/memoryexample.cpp b/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/CPP/memoryexample.cpp deleted file mode 100644 index 1d26f0f096b..00000000000 --- a/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/CPP/memoryexample.cpp +++ /dev/null @@ -1,105 +0,0 @@ - -// -using namespace System; -using namespace System::Security::Cryptography; -using namespace System::Text; -using namespace System::IO; -array^ EncryptTextToMemory( String^ Data, array^Key, array^IV ) -{ - try - { - - // Create a MemoryStream. - MemoryStream^ mStream = gcnew MemoryStream; - - // Create a CryptoStream using the MemoryStream - // and the passed key and initialization vector (IV). - CryptoStream^ cStream = gcnew CryptoStream( mStream,(gcnew TripleDESCryptoServiceProvider)->CreateEncryptor( Key, IV ),CryptoStreamMode::Write ); - - // Convert the passed string to a byte array. - array^toEncrypt = (gcnew ASCIIEncoding)->GetBytes( Data ); - - // Write the byte array to the crypto stream and flush it. - cStream->Write( toEncrypt, 0, toEncrypt->Length ); - cStream->FlushFinalBlock(); - - // Get an array of bytes from the - // MemoryStream that holds the - // encrypted data. - array^ret = mStream->ToArray(); - - // Close the streams. - cStream->Close(); - mStream->Close(); - - // Return the encrypted buffer. - return ret; - } - catch ( CryptographicException^ e ) - { - Console::WriteLine( "A Cryptographic error occurred: {0}", e->Message ); - return nullptr; - } - -} - -String^ DecryptTextFromMemory( array^Data, array^Key, array^IV ) -{ - try - { - - // Create a new MemoryStream using the passed - // array of encrypted data. - MemoryStream^ msDecrypt = gcnew MemoryStream( Data ); - - // Create a CryptoStream using the MemoryStream - // and the passed key and initialization vector (IV). - CryptoStream^ csDecrypt = gcnew CryptoStream( msDecrypt,(gcnew TripleDESCryptoServiceProvider)->CreateDecryptor( Key, IV ),CryptoStreamMode::Read ); - - // Create buffer to hold the decrypted data. - array^fromEncrypt = gcnew array(Data->Length); - - // Read the decrypted data out of the crypto stream - // and place it into the temporary buffer. - csDecrypt->Read( fromEncrypt, 0, fromEncrypt->Length ); - - //Convert the buffer into a string and return it. - return (gcnew ASCIIEncoding)->GetString( fromEncrypt ); - } - catch ( CryptographicException^ e ) - { - Console::WriteLine( "A Cryptographic error occurred: {0}", e->Message ); - return nullptr; - } - -} - -int main() -{ - try - { - - // Create a new TripleDESCryptoServiceProvider object - // to generate a key and initialization vector (IV). - TripleDESCryptoServiceProvider^ tDESalg = gcnew TripleDESCryptoServiceProvider; - - // Create a string to encrypt. - String^ sData = "Here is some data to encrypt."; - - // Encrypt the string to an in-memory buffer. - array^Data = EncryptTextToMemory( sData, tDESalg->Key, tDESalg->IV ); - - // Decrypt the buffer back to a string. - String^ Final = DecryptTextFromMemory( Data, tDESalg->Key, tDESalg->IV ); - - // Display the decrypted string to the console. - Console::WriteLine( Final ); - } - catch ( Exception^ e ) - { - Console::WriteLine( e->Message ); - } - -} - -// diff --git a/snippets/cpp/VS_Snippets_CLR_Classic/classic TripleDESCryptoServiceProvider Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_CLR_Classic/classic TripleDESCryptoServiceProvider Example/CPP/source.cpp deleted file mode 100644 index 2caa6452d62..00000000000 --- a/snippets/cpp/VS_Snippets_CLR_Classic/classic TripleDESCryptoServiceProvider Example/CPP/source.cpp +++ /dev/null @@ -1,43 +0,0 @@ - - -#using - -using namespace System; -using namespace System::IO; -using namespace System::ComponentModel; -using namespace System::Security::Cryptography; - -// -void EncryptData( String^ inName, String^ outName, array^tdesKey, array^tdesIV ) -{ - - //Create the file streams to handle the input and output files. - FileStream^ fin = gcnew FileStream( inName,FileMode::Open,FileAccess::Read ); - FileStream^ fout = gcnew FileStream( outName,FileMode::OpenOrCreate,FileAccess::Write ); - fout->SetLength( 0 ); - - //Create variables to help with read and write. - array^bin = gcnew array(100); - long rdlen = 0; //This is the total number of bytes written. - - long totlen = (long)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. - - TripleDESCryptoServiceProvider^ tdes = gcnew TripleDESCryptoServiceProvider; - CryptoStream^ encStream = gcnew CryptoStream( fout,tdes->CreateEncryptor( tdesKey, tdesIV ),CryptoStreamMode::Write ); - Console::WriteLine( "Encrypting..." ); - - //Read from the input file, then encrypt and write to the output file. - while ( rdlen < totlen ) - { - len = fin->Read( bin, 0, 100 ); - encStream->Write( bin, 0, len ); - rdlen = rdlen + len; - Console::WriteLine( "{0} bytes processed", rdlen ); - } - - encStream->Close(); -} - -// diff --git a/snippets/csharp/System.Security.Cryptography/TripleDES/Overview/Project.csproj b/snippets/csharp/System.Security.Cryptography/TripleDES/Overview/Project.csproj deleted file mode 100644 index c02dc5044e7..00000000000 --- a/snippets/csharp/System.Security.Cryptography/TripleDES/Overview/Project.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Library - net6.0 - - - \ No newline at end of file diff --git a/snippets/csharp/System.Security.Cryptography/TripleDES/Overview/source.cs b/snippets/csharp/System.Security.Cryptography/TripleDES/Overview/source.cs deleted file mode 100644 index 2066c68c338..00000000000 --- a/snippets/csharp/System.Security.Cryptography/TripleDES/Overview/source.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.IO; -using System.ComponentModel; -using System.Security.Cryptography; - -public class Sample -{ -// - private static void EncryptData(string inName, string outName, byte[] tdesKey, byte[] tdesIV) - { - //Create the file streams to handle the input and output files. - FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read); - FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write); - fout.SetLength(0); - - //Create variables to help with read and write. - byte[] bin = new byte[100]; //This is intermediate storage for the encryption. - long rdlen = 0; //This is the total number of bytes written. - 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. - - TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider(); - CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(tdesKey, tdesIV), CryptoStreamMode.Write); - - Console.WriteLine("Encrypting..."); - - //Read from the input file, then encrypt and write to the output file. - while(rdlen < totlen) - { - len = fin.Read(bin, 0, 100); - encStream.Write(bin, 0, len); - rdlen = rdlen + len; - Console.WriteLine("{0} bytes processed", rdlen); - } - - encStream.Close(); - } -// -} diff --git a/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/fileexample.cs b/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/fileexample.cs deleted file mode 100644 index 7f087762f75..00000000000 --- a/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/fileexample.cs +++ /dev/null @@ -1,114 +0,0 @@ -// -using System; -using System.Security.Cryptography; -using System.Text; -using System.IO; - -class TrippleDESCSPSample -{ - - static void Main() - { - try - { - // Create a new TripleDESCryptoServiceProvider object - // to generate a key and initialization vector (IV). - TripleDESCryptoServiceProvider tDESalg = new TripleDESCryptoServiceProvider(); - - // Create a string to encrypt. - string sData = "Here is some data to encrypt."; - string FileName = "CText.txt"; - - // Encrypt text to a file using the file name, key, and IV. - EncryptTextToFile(sData, FileName, tDESalg.Key, tDESalg.IV); - - // Decrypt the text from a file using the file name, key, and IV. - string Final = DecryptTextFromFile(FileName, tDESalg.Key, tDESalg.IV); - - // Display the decrypted string to the console. - Console.WriteLine(Final); - } - catch (Exception e) - { - Console.WriteLine(e.Message); - } - } - - public static void EncryptTextToFile(String Data, String FileName, byte[] Key, byte[] IV) - { - try - { - // Create or open the specified file. - FileStream fStream = File.Open(FileName,FileMode.OpenOrCreate); - - // Create a CryptoStream using the FileStream - // and the passed key and initialization vector (IV). - CryptoStream cStream = new CryptoStream(fStream, - new TripleDESCryptoServiceProvider().CreateEncryptor(Key,IV), - CryptoStreamMode.Write); - - // Create a StreamWriter using the CryptoStream. - StreamWriter sWriter = new StreamWriter(cStream); - - // Write the data to the stream - // to encrypt it. - sWriter.WriteLine(Data); - - // Close the streams and - // close the file. - sWriter.Close(); - cStream.Close(); - fStream.Close(); - } - catch(CryptographicException e) - { - Console.WriteLine("A Cryptographic error occurred: {0}", e.Message); - } - catch(UnauthorizedAccessException e) - { - Console.WriteLine("A file access error occurred: {0}", e.Message); - } - } - - public static string DecryptTextFromFile(String FileName, byte[] Key, byte[] IV) - { - try - { - // Create or open the specified file. - FileStream fStream = File.Open(FileName, FileMode.OpenOrCreate); - - // Create a CryptoStream using the FileStream - // and the passed key and initialization vector (IV). - CryptoStream cStream = new CryptoStream(fStream, - new TripleDESCryptoServiceProvider().CreateDecryptor(Key,IV), - CryptoStreamMode.Read); - - // Create a StreamReader using the CryptoStream. - StreamReader sReader = new StreamReader(cStream); - - // Read the data from the stream - // to decrypt it. - string val = sReader.ReadLine(); - - // Close the streams and - // close the file. - sReader.Close(); - cStream.Close(); - fStream.Close(); - - // Return the string. - return val; - } - catch(CryptographicException e) - { - Console.WriteLine("A Cryptographic error occurred: {0}", e.Message); - return null; - } - catch(UnauthorizedAccessException e) - { - Console.WriteLine("A file access error occurred: {0}", e.Message); - return null; - } - } -} -// \ No newline at end of file diff --git a/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/memoryexample.cs b/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/memoryexample.cs deleted file mode 100644 index c48a200e792..00000000000 --- a/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/memoryexample.cs +++ /dev/null @@ -1,106 +0,0 @@ -// -using System; -using System.Security.Cryptography; -using System.Text; -using System.IO; - -class TrippleDESCSPSample -{ - - static void Main() - { - try - { - // Create a new TripleDESCryptoServiceProvider object - // to generate a key and initialization vector (IV). - TripleDESCryptoServiceProvider tDESalg = new TripleDESCryptoServiceProvider(); - - // Create a string to encrypt. - string sData = "Here is some data to encrypt."; - - // Encrypt the string to an in-memory buffer. - byte[] Data = EncryptTextToMemory(sData, tDESalg.Key, tDESalg.IV); - - // Decrypt the buffer back to a string. - string Final = DecryptTextFromMemory(Data, tDESalg.Key, tDESalg.IV); - - // Display the decrypted string to the console. - Console.WriteLine(Final); - } - catch (Exception e) - { - Console.WriteLine(e.Message); - } - } - - public static byte[] EncryptTextToMemory(string Data, byte[] Key, byte[] IV) - { - try - { - // Create a MemoryStream. - MemoryStream mStream = new MemoryStream(); - - // Create a CryptoStream using the MemoryStream - // and the passed key and initialization vector (IV). - CryptoStream cStream = new CryptoStream(mStream, - new TripleDESCryptoServiceProvider().CreateEncryptor(Key, IV), - CryptoStreamMode.Write); - - // Convert the passed string to a byte array. - byte[] toEncrypt = new ASCIIEncoding().GetBytes(Data); - - // Write the byte array to the crypto stream and flush it. - cStream.Write(toEncrypt, 0, toEncrypt.Length); - cStream.FlushFinalBlock(); - - // Get an array of bytes from the - // MemoryStream that holds the - // encrypted data. - byte[] ret = mStream.ToArray(); - - // Close the streams. - cStream.Close(); - mStream.Close(); - - // Return the encrypted buffer. - return ret; - } - catch(CryptographicException e) - { - Console.WriteLine("A Cryptographic error occurred: {0}", e.Message); - return null; - } - } - - public static string DecryptTextFromMemory(byte[] Data, byte[] Key, byte[] IV) - { - try - { - // Create a new MemoryStream using the passed - // array of encrypted data. - MemoryStream msDecrypt = new MemoryStream(Data); - - // Create a CryptoStream using the MemoryStream - // and the passed key and initialization vector (IV). - CryptoStream csDecrypt = new CryptoStream(msDecrypt, - new TripleDESCryptoServiceProvider().CreateDecryptor(Key, IV), - CryptoStreamMode.Read); - - // Create buffer to hold the decrypted data. - byte[] fromEncrypt = new byte[Data.Length]; - - // Read the decrypted data out of the crypto stream - // and place it into the temporary buffer. - csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length); - - //Convert the buffer into a string and return it. - return new ASCIIEncoding().GetString(fromEncrypt); - } - catch(CryptographicException e) - { - Console.WriteLine("A Cryptographic error occurred: {0}", e.Message); - return null; - } - } -} -// diff --git a/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.File/VB/project.csproj b/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.File/VB/project.vbproj similarity index 100% rename from snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.File/VB/project.csproj rename to snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.File/VB/project.vbproj diff --git a/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.Memory/project.csproj b/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.Memory/project.vbproj similarity index 100% rename from snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.Memory/project.csproj rename to snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.Memory/project.vbproj diff --git a/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/VB/fileexample.vb b/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/VB/fileexample.vb deleted file mode 100644 index abf5d60b8a5..00000000000 --- a/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/VB/fileexample.vb +++ /dev/null @@ -1,98 +0,0 @@ - ' -Imports System.Security.Cryptography -Imports System.Text -Imports System.IO - -Module TrippleDESCSPSample - - Sub Main() - Try - ' Create a new TripleDESCryptoServiceProvider object - ' to generate a key and initialization vector (IV). - Dim tDESalg As New TripleDESCryptoServiceProvider - - ' Create a string to encrypt. - Dim sData As String = "Here is some data to encrypt." - Dim FileName As String = "CText.txt" - - ' Encrypt text to a file using the file name, key, and IV. - EncryptTextToFile(sData, FileName, tDESalg.Key, tDESalg.IV) - - ' Decrypt the text from a file using the file name, key, and IV. - Dim Final As String = DecryptTextFromFile(FileName, tDESalg.Key, tDESalg.IV) - - ' Display the decrypted string to the console. - Console.WriteLine(Final) - Catch e As Exception - Console.WriteLine(e.Message) - End Try - End Sub - - - Sub EncryptTextToFile(ByVal Data As String, ByVal FileName As String, ByVal Key() As Byte, ByVal IV() As Byte) - Try - ' Create or open the specified file. - Dim fStream As FileStream = File.Open(FileName, FileMode.OpenOrCreate) - - ' Create a CryptoStream using the FileStream - ' and the passed key and initialization vector (IV). - Dim cStream As New CryptoStream(fStream, _ - New TripleDESCryptoServiceProvider().CreateEncryptor(Key, IV), _ - CryptoStreamMode.Write) - - ' Create a StreamWriter using the CryptoStream. - Dim sWriter As New StreamWriter(cStream) - - ' Write the data to the stream - ' to encrypt it. - sWriter.WriteLine(Data) - - ' Close the streams and - ' close the file. - sWriter.Close() - cStream.Close() - fStream.Close() - Catch e As CryptographicException - Console.WriteLine("A Cryptographic error occurred: {0}", e.Message) - Catch e As UnauthorizedAccessException - Console.WriteLine("A file error occurred: {0}", e.Message) - End Try - End Sub - - - Function DecryptTextFromFile(ByVal FileName As String, ByVal Key() As Byte, ByVal IV() As Byte) As String - Try - ' Create or open the specified file. - Dim fStream As FileStream = File.Open(FileName, FileMode.OpenOrCreate) - - ' Create a CryptoStream using the FileStream - ' and the passed key and initialization vector (IV). - Dim cStream As New CryptoStream(fStream, _ - New TripleDESCryptoServiceProvider().CreateDecryptor(Key, IV), _ - CryptoStreamMode.Read) - - ' Create a StreamReader using the CryptoStream. - Dim sReader As New StreamReader(cStream) - - ' Read the data from the stream - ' to decrypt it. - Dim val As String = sReader.ReadLine() - - ' Close the streams and - ' close the file. - sReader.Close() - cStream.Close() - fStream.Close() - - ' Return the string. - Return val - Catch e As CryptographicException - Console.WriteLine("A Cryptographic error occurred: {0}", e.Message) - Return Nothing - Catch e As UnauthorizedAccessException - Console.WriteLine("A file error occurred: {0}", e.Message) - Return Nothing - End Try - End Function -End Module - ' \ No newline at end of file diff --git a/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/VB/memoryexample.vb b/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/VB/memoryexample.vb deleted file mode 100644 index 94ea1e8c7e1..00000000000 --- a/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/VB/memoryexample.vb +++ /dev/null @@ -1,94 +0,0 @@ - ' -Imports System.Security.Cryptography -Imports System.Text -Imports System.IO - -Module TrippleDESCSPSample - - Sub Main() - Try - ' Create a new TripleDESCryptoServiceProvider object - ' to generate a key and initialization vector (IV). - Dim tDESalg As New TripleDESCryptoServiceProvider - - ' Create a string to encrypt. - Dim sData As String = "Here is some data to encrypt." - - ' Encrypt the string to an in-memory buffer. - Dim Data As Byte() = EncryptTextToMemory(sData, tDESalg.Key, tDESalg.IV) - - ' Decrypt the buffer back to a string. - Dim Final As String = DecryptTextFromMemory(Data, tDESalg.Key, tDESalg.IV) - - ' Display the decrypted string to the console. - Console.WriteLine(Final) - Catch e As Exception - Console.WriteLine(e.Message) - End Try - End Sub - - - Function EncryptTextToMemory(ByVal Data As String, ByVal Key() As Byte, ByVal IV() As Byte) As Byte() - Try - ' Create a MemoryStream. - Dim mStream As New MemoryStream - - ' Create a CryptoStream using the MemoryStream - ' and the passed key and initialization vector (IV). - Dim cStream As New CryptoStream(mStream, _ - New TripleDESCryptoServiceProvider().CreateEncryptor(Key, IV), _ - CryptoStreamMode.Write) - - ' Convert the passed string to a byte array. - Dim toEncrypt As Byte() = New ASCIIEncoding().GetBytes(Data) - - ' Write the byte array to the crypto stream and flush it. - cStream.Write(toEncrypt, 0, toEncrypt.Length) - cStream.FlushFinalBlock() - - ' Get an array of bytes from the - ' MemoryStream that holds the - ' encrypted data. - Dim ret As Byte() = mStream.ToArray() - - ' Close the streams. - cStream.Close() - mStream.Close() - - ' Return the encrypted buffer. - Return ret - Catch e As CryptographicException - Console.WriteLine("A Cryptographic error occurred: {0}", e.Message) - Return Nothing - End Try - End Function - - - Function DecryptTextFromMemory(ByVal Data() As Byte, ByVal Key() As Byte, ByVal IV() As Byte) As String - Try - ' Create a new MemoryStream using the passed - ' array of encrypted data. - Dim msDecrypt As New MemoryStream(Data) - - ' Create a CryptoStream using the MemoryStream - ' and the passed key and initialization vector (IV). - Dim csDecrypt As New CryptoStream(msDecrypt, _ - New TripleDESCryptoServiceProvider().CreateDecryptor(Key, IV), _ - CryptoStreamMode.Read) - - ' Create buffer to hold the decrypted data. - Dim fromEncrypt(Data.Length - 1) As Byte - - ' Read the decrypted data out of the crypto stream - ' and place it into the temporary buffer. - csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length) - - 'Convert the buffer into a string and return it. - Return New ASCIIEncoding().GetString(fromEncrypt) - Catch e As CryptographicException - Console.WriteLine("A Cryptographic error occurred: {0}", e.Message) - Return Nothing - End Try - End Function -End Module - ' \ No newline at end of file diff --git a/snippets/visualbasic/VS_Snippets_CLR_Classic/classic TripleDESCryptoServiceProvider Example/VB/source.vb b/snippets/visualbasic/VS_Snippets_CLR_Classic/classic TripleDESCryptoServiceProvider Example/VB/source.vb deleted file mode 100644 index 7023c3dc158..00000000000 --- a/snippets/visualbasic/VS_Snippets_CLR_Classic/classic TripleDESCryptoServiceProvider Example/VB/source.vb +++ /dev/null @@ -1,39 +0,0 @@ -Imports System.IO -Imports System.ComponentModel -Imports System.Security.Cryptography - -Public Class Sample - -' -Private Shared Sub EncryptData(inName As String, outName As String, _ - tdesKey() As Byte, tdesIV() As Byte) - - 'Create the file streams to handle the input and output files. - Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read) - Dim fout As New FileStream(outName, FileMode.OpenOrCreate, _ - FileAccess.Write) - fout.SetLength(0) - - 'Create variables to help with read and write. - Dim bin(100) As Byte 'This is intermediate storage for the encryption. - Dim rdlen As Long = 0 'This is the total number of bytes written. - Dim totlen As Long = fin.Length 'This is the total length of the input file. - Dim len As Integer 'This is the number of bytes to be written at a time. - Dim tdes As New TripleDESCryptoServiceProvider() - Dim encStream As New CryptoStream(fout, _ - tdes.CreateEncryptor(tdesKey, tdesIV), CryptoStreamMode.Write) - - Console.WriteLine("Encrypting...") - - 'Read from the input file, then encrypt and write to the output file. - While rdlen < totlen - len = fin.Read(bin, 0, 100) - encStream.Write(bin, 0, len) - rdlen = rdlen + len - Console.WriteLine("{0} bytes processed", rdlen) - End While - - encStream.Close() -End Sub -' -End Class diff --git a/xml/System.Security.Cryptography/TripleDES.xml b/xml/System.Security.Cryptography/TripleDES.xml index 75acf1733d6..ae3b04001f5 100644 --- a/xml/System.Security.Cryptography/TripleDES.xml +++ b/xml/System.Security.Cryptography/TripleDES.xml @@ -81,14 +81,17 @@ ## Examples - The following code example method uses with the specified key () and initialization vector () to encrypt a file specified by `inName`. It then outputs the encrypted result to the file specified by `outName`. + The following code example shows how to create and use a object to encrypt and decrypt data in a file. - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic TripleDESCryptoServiceProvider Example/CPP/source.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDES/Overview/source.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic TripleDESCryptoServiceProvider Example/VB/source.vb" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDES/Create/fileexample.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.File/VB/fileexample.vb" id="Snippet1"::: - Decryption can be handled in the same way; use instead of . The same key () and initialization vector () used to encrypt the file must be used to decrypt it. + The following code example shows how to create and use a object to encrypt and decrypt data in memory. + :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDES/Create/memoryexample.cs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.Memory/VB/memoryexample.vb" id="Snippet1"::: + + ]]> @@ -242,7 +245,7 @@ The following code example shows how to create and use a object to encrypt and decrypt data in memory. - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DES.Create.Memory/CPP/memoryexample.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDES/Create/memoryexample.cs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DES.Create.Memory/VB/memoryexample.vb" id="Snippet1"::: ]]> diff --git a/xml/System.Security.Cryptography/TripleDESCryptoServiceProvider.xml b/xml/System.Security.Cryptography/TripleDESCryptoServiceProvider.xml index 1e22ba85c31..41c0edcaa4a 100644 --- a/xml/System.Security.Cryptography/TripleDESCryptoServiceProvider.xml +++ b/xml/System.Security.Cryptography/TripleDESCryptoServiceProvider.xml @@ -73,26 +73,11 @@ method instead. + > [!NOTE] > A newer symmetric encryption algorithm, Advanced Encryption Standard (AES), is available. Consider using the class instead of the class. Use only for compatibility with legacy applications and data. - - -## Examples - The following code example creates a object and uses it to encrypt and decrypt data in a file. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/CPP/fileexample.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/fileexample.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/VB/fileexample.vb" id="Snippet1"::: - - The following code example creates a object and uses it to encrypt and decrypt data in memory. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/CPP/memoryexample.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/memoryexample.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/VB/memoryexample.vb" id="Snippet1"::: - ]]> Cryptographic Services @@ -144,18 +129,8 @@ object and uses it to encrypt and decrypt data in a file. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/CPP/fileexample.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/fileexample.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/VB/fileexample.vb" id="Snippet1"::: - - The following code example creates a object and uses it to encrypt and decrypt data in memory. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/CPP/memoryexample.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/memoryexample.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/VB/memoryexample.vb" id="Snippet1"::: +## Remarks +`TripleDESCryptoServiceProvider` is obsolete. Use the method instead. ]]> @@ -315,22 +290,7 @@ overload with the same parameters. - - - -## Examples - The following code example creates a object and uses it to encrypt and decrypt data in a file. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/CPP/fileexample.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/fileexample.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/VB/fileexample.vb" id="Snippet1"::: - - The following code example creates a object and uses it to encrypt and decrypt data in memory. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/CPP/memoryexample.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/memoryexample.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/VB/memoryexample.vb" id="Snippet1"::: + This method decrypts an encrypted message created using the overload with the same parameters. ]]> @@ -471,22 +431,7 @@ overload with the same parameters to decrypt the result of this method. - - - -## Examples - The following code example creates a object and uses it to encrypt and decrypt data in a file. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/CPP/fileexample.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/fileexample.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.File/VB/fileexample.vb" id="Snippet1"::: - - The following code example creates a object and uses it to encrypt and decrypt data in memory. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/CPP/memoryexample.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography/TripleDESCryptoServiceProvider/Overview/memoryexample.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Cryptography.3DESCSP.CreateEncryptor.Memory/VB/memoryexample.vb" id="Snippet1"::: + Use the overload with the same parameters to decrypt the result of this method. ]]>