I have a .NET string which is Base64 encoded representation of an array of encrypted bytes. It is produced like this:
String Encrypt( String message )
{
CryptoStream cryptostream = ...
StreamWriter stream = new StreamWriter( cryptostream );
...
return Convert.ToBase64String( ... );
}
Now I want a decryption function like
String Decrypt( String cypher )
{
TextReader reader = new StringReader( cypher );
byte[] buffer = new byte[ cypher.Length ];
for( int i = 0; i < cypher.Length; ++i )
{
buffer[ i ] = (byte) reader.Read();
}
FromBase64Transform transformer = new FromBase64Transform();
MemoryStream raw = new MemoryStream
(
transformer.TransformFinalBlock( buffer, 0, buffer.Length )
);
...
}
Is there a way to use FromBase64Transform directly with CryptoStream (as the .NET documentation suggests), instead of manually converting the string to bytes, then manually decoding the bytes, and finally decrypting the decoded bytes?