why use cryptstream in a tripleDES envrypt?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kennet madsen

    #1

    why use cryptstream in a tripleDES envrypt?

    i am working on a encrypt method for a company. and i have gotten there own encrypt method.. and i am new to encrypting so i want to know why they use a cryptoStream..
    code is below:

    Code:
    public static string EncryptFromText(string plainText, byte[] IVKey)
    {
    	//Declare a UTF8Encoding object so we may use the GetByte method to transform the plainText into a Byte array.
    
    	System.Text.UTF8Encoding utf8encoder = new System.Text.UTF8Encoding();
    
    	byte[] inputInBytes = utf8encoder.GetBytes(plainText);
    
    	System.Security.Cryptography.TripleDESCryptoServiceProvider tdesProvider = new System.Security.Cryptography.TripleDESCryptoServiceProvider();
    
    	System.Security.Cryptography.ICryptoTransform cryptoTransform = tdesProvider.CreateEncryptor(symKey, IVKey);
    
    
    	System.IO.MemoryStream encryptedStream = new System.IO.MemoryStream();
    
    	System.Security.Cryptography.CryptoStream cryptStream = new System.Security.Cryptography.CryptoStream(encryptedStream, cryptoTransform, System.Security.Cryptography.CryptoStreamMode.Write);
    
    
    	cryptStream.Write(inputInBytes, 0, inputInBytes.Length);
    
    	cryptStream.FlushFinalBlock();
    
    	encryptedStream.Position = 0;
    
    	byte[] result = new byte[encryptedStream.Length];
    
    	encryptedStream.Read(result, 0, encryptedStream.Length);
    
    	cryptStream.Close();
    
    	return GetStringFromByte(result);
    
    }
Working...