Questions tagged [cryptostream]
83 questions
1
vote
1 answer
C# CryptoStream result not as expected
I'm trying to understand why the following code results in the encrypted byte array being 16 bytes if plainText is 8 bytes in length. I expected the result to also be 8 bytes in length?
private static byte[] encrypt(byte[] key, byte[] plainText)
{
…

Taylor Leese
- 51,004
- 28
- 112
- 141
0
votes
1 answer
Crypto stream: read data error
I got this (i also tried crStream.CopyTo(ms)):
var cryptic = new DESCryptoServiceProvider();
cryptic.Key = ASCIIEncoding.ASCII.GetBytes(passKey);
cryptic.IV = ASCIIEncoding.ASCII.GetBytes(passKey);
Stream crStream = new CryptoStream(data,…

Patrick
- 5,442
- 9
- 53
- 104
0
votes
1 answer
Exception thrown when CryptoStream instance closed
I have a DecryptString function that uses the RijndaelManaged Cipher. It works 99.999% of the time but very occationally it throws an "IndexOutOfRangeException" exception with the message of "Index was outside the bounds of the array." when it…

Jonathan Stanton
- 2,531
- 1
- 28
- 35
0
votes
1 answer
Why can't I decrypt data using RijndaelManaged?
I'm working on a program that sends and receives messages just like messengers, and I need to encrypt the message on send button and decrypt the message when received. I'm using the RijndaelManaged class and the following methods to encrypt/decrypt
…

Lisa
- 3,121
- 15
- 53
- 85
0
votes
1 answer
CryptoStream.FlushFinalBlock throwing input data is not a complete block exception
I use the following two methods to encrypt and decrypt strings:
'Encrypts string. Returns encrypted byte array.
Public Function Encrypt(ByVal str As String) As Byte()
Dim inputInBytes() As Byte = Encoding.Unicode.GetBytes(str)
Dim…

gsxrboy73
- 1,382
- 14
- 19
0
votes
0 answers
Decrypt chipperText with Salt returns partial result on .NET 7
There is a similar question here Problem Updating to .Net 6 - Encrypting String
But it is not same as what I am facing.
My plain text is as below
+6+HGeVqjF6OwJzD/bKZaLyORmYBu0o/uk1Tj0T3ksI=
Encrypted it using below code
private string…

HaBo
- 13,999
- 36
- 114
- 206
0
votes
0 answers
C# CryptoStream.Close() writes additional block into an attached MemoryStream
I have an encryption function based on the standard library AES with the block size of 16 bytes.
I'm encrypting a single block of size 16 bytes with a 16 byte key, using CryptoStream and MemoryStream.
If I Write and Flush, the result has 16 bytes.…

Adam Streck
- 340
- 2
- 15
0
votes
0 answers
OutOfMemoryException while using CryptoStream with large Strings in VB.NET
my program runs into a OutOfMemoryException when I use large Strings with the following method.
Public Function EncryptData(ByVal plaintext As String) As String
Dim plaintextBytes() As Byte =…

NiklasV
- 1
- 1
0
votes
1 answer
Work With HashAlgorithm as an implementation of ICryptoTransform in .Net
According to Microsoft documentation, HashAlgorithm class implement ICryptoTransform interface, so we should be able to use it with CryptoStream. But when I use it, I get the input stream without any hashing. Where is my mistake?
My code is as…

Mehdi Mowlavi
- 434
- 1
- 11
0
votes
0 answers
CryptoStream behaves differently on local and aws
I have encryption decryption code which is perfectly working fine in local. From local system using code first approach I created database in aws which created successfully with seeds values in which I have decrypted the password.
Now, I have…

Fahad Altaf
- 1
- 2
0
votes
0 answers
How to Hash Filestream while writing to file?
in C# I am using Filestream to write to a new file. I am then hashing this file to get SHA256 hash to verify later. I would like to remove this extra file read, and simply hash file as it is being streamed.
using (FileStream fs = new…

Jaren L
- 1
- 1
0
votes
1 answer
Unable to resolve compression, encryption, decryption, decompression stream implementation
I've been fighting with chained using statements, and am unable to resolve the latest in a long line of implementation issues. I need to compress, then encrypt and append the generated IV to the selected file. This all appears to work correctly,…

Reahreic
- 596
- 2
- 7
- 26
0
votes
1 answer
call Dispose() function after FlushFinalBlock()?
I have the following code:
Public Shared Function Crypt(text As String) As String
If text <> "" Then
Dim cryptoProvider As New DESCryptoServiceProvider()
Dim ms As New MemoryStream()
Dim cs As New CryptoStream(ms,…

Luis Jasso
- 3
- 1
- 3
0
votes
1 answer
ReadAsync is emptying stream
So, I had this code working fine for communication between a client/server program. The communication is done with one byte buffer that has two elements, an int that specifies how many bytes follow, and the "payload". If I use my
debugger to step…

Alexis Shepard
- 63
- 1
- 7
0
votes
0 answers
How to use buffer with cryptostream | AES encrypting
I tried to implement this code to encrypt and decrypt streams. Everything worked fine until I implemented buffer. Than when I try decrypting, an 'Invalid padding' error is thrown.
Does anyone know why this happens. Or is there another way of…

daralim
- 183
- 10