cryptostream

DeflateStream / GZipStream to CryptoStream and vice versa

☆樱花仙子☆ 提交于 2021-02-07 09:33:39
问题 I want to to compress and encrypt a file in one go by using this simple code: public void compress(FileInfo fi, Byte[] pKey, Byte[] pIV) { // Get the stream of the source file. using (FileStream inFile = fi.OpenRead()) { // Create the compressed encrypted file. using (FileStream outFile = File.Create(fi.FullName + ".pebf")) { using (CryptoStream encrypt = new CryptoStream(outFile, Rijndael.Create().CreateEncryptor(pKey, pIV), CryptoStreamMode.Write)) { using (DeflateStream cmprss = new

DeflateStream / GZipStream to CryptoStream and vice versa

寵の児 提交于 2021-02-07 09:30:42
问题 I want to to compress and encrypt a file in one go by using this simple code: public void compress(FileInfo fi, Byte[] pKey, Byte[] pIV) { // Get the stream of the source file. using (FileStream inFile = fi.OpenRead()) { // Create the compressed encrypted file. using (FileStream outFile = File.Create(fi.FullName + ".pebf")) { using (CryptoStream encrypt = new CryptoStream(outFile, Rijndael.Create().CreateEncryptor(pKey, pIV), CryptoStreamMode.Write)) { using (DeflateStream cmprss = new

CryptoStream: Why CryptoStreamMode.Write to encrypt and CryptoStreamMode.Read to decrypt?

别来无恙 提交于 2020-08-03 09:12:31
问题 Let e = 'password' and I am transforming it to 'as9kio0736' in a CryptoStream. Let d = 'as9kio0736' and I am transforming it to 'password in a CryptoStream. When I am transforming d back to 'password' why is it not considered writing in a CryptoStream? using (MemoryStream msEncrypt = new MemoryStream()) { using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) { swEncrypt.Write(plainText); }

Issue deserializing encrypted data using BinaryFormatter

廉价感情. 提交于 2019-12-31 03:09:03
问题 Here is my code: public static void Save<T>(T toSerialize, string fileSpec) { BinaryFormatter formatter = new BinaryFormatter(); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); using (FileStream stream = File.Create(fileSpec)) { using (CryptoStream cryptoStream = new CryptoStream(stream, des.CreateEncryptor(key, iv), CryptoStreamMode.Write)) { formatter.Serialize(cryptoStream, toSerialize); cryptoStream.FlushFinalBlock(); } } } public static T Load<T>(string fileSpec) {

C# “Bad Data” exception when decrypting encrypted file

一个人想着一个人 提交于 2019-12-30 11:12:11
问题 Hey I'm very new to encryption and decryption, or even the c# language to be honest. Basically, I have a tcp chat server that "saves" logs and encrypts the text file. This is how I encrypt (based from the MSDN sample): public static void EncryptFile(string strInputFileName, string strOutputFileName, string strKey) { FileStream fsIn = new FileStream(strInputFileName, FileMode.Open, FileAccess.Read); FileStream fsOut = new FileStream(strOutputFileName, FileMode.Create, FileAccess.Write);

Please how can i return decoded bytes instead of text from a CryptoStream

守給你的承諾、 提交于 2019-12-13 08:53:45
问题 Please how can i return the decoded bytes instead of text in the following snippet: Public Shared Function decryptAsText(key As Byte(), ciphertext As Byte(), iv As Byte()) As String Dim dec As String = Nothing Try Using rj = New Security.Cryptography.RijndaelManaged With {.Key = key, .IV = iv, .Mode = Security.Cryptography.CipherMode.CBC, .Padding = PaddingMode.PKCS7} Using ms = New IO.MemoryStream(ciphertext) Using cs = New Security.Cryptography.CryptoStream(ms, rj.CreateDecryptor(key, iv),

CryptoStream does not decrypt properly

空扰寡人 提交于 2019-12-12 01:42:32
问题 I have a working TCP-connection between a server application and a client, wich communicate encrypted with AES. it works with an CryptoStream having an RijndaelManaged En/Decrypter. well Right now, if i want to send sth. like this: "F4FBF-B60FC-6F3ED-1E5A9" i get that as output : "Ü]Þí£ôÉò×â×$¼ÚD-1E5A9" so... what could be going wrong here? why is that still encryptet up to "D-1E5A9"? Well here some Code: Server: while (true) { Console.Write("Waiting for a connection... "); TcpClient client =

Decrypting CryptoStream into MemoryStream

丶灬走出姿态 提交于 2019-12-11 20:51:50
问题 I have written a process where a file is encrypted and uploaded to Azure, then the download process has to be decrypted which is what fails with a "Padding is invalid and cannot be removed" error, or a "Length of the data to decrypt is invalid." error. I've tried numerous solutions online, including C# Decrypting mp3 file using RijndaelManaged and CryptoStream, but none of them seem to work and I end up just bouncing back and forth between these two errors. The encryption process uses the

Encrypting and Decrypting String using a Java equilavent of the C# CryptoStream

南楼画角 提交于 2019-12-03 19:40:32
问题 I am looking at developing an application in Java for a mobile platform operating system. I have developed an application in C# WPF for the Windows Environment. I am using a cryptostream in order to encrypt and decrypt a string using the following code. the code shown below is the encryption only public string encrypt(string encryptionString) { byte[] clearTextBytes = Encoding.UTF8.GetBytes(encryptionString); SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); MemoryStream ms = new

Reuse ICryptoTransform objects

℡╲_俬逩灬. 提交于 2019-12-01 19:57:01
I have a class that is used to encrypt textual data. I am trying to reuse the ICryptoTransform objects where possible. However, the second time I am trying to use the same object, I get partially incorrectly decrypted data. I think the first block is wrong but the rest seems to be okay (tested it with longer texts). I stripped down the class to the following: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; namespace Sample.Crypto { public class EncryptedStreamResolver : IDisposable { private