473,785 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Crypto removing white spaces from byte array

I'm sorry if this is the wrong group but I couldn't find one relating to
cryptography.

I have a byte array that I am encrypting using the System.Cryptogr aphy
classes and it encrypts just fine. However when I decrypt the array the
decryptor removes all the white spaces from the array (byte values of 255).
I've tried setting the padding to none but it doesn't work. As long as the
array doesn't have any white spaces in there it encrypts and decrypts
normally.

Anyone have any ideas on how to fix this?

Thanks!!

Brian


Jun 2 '06 #1
1 1952

Brian Mitchell wrote:
I have a byte array that I am encrypting using the System.Cryptogr aphy
classes and it encrypts just fine. However when I decrypt the array the
decryptor removes all the white spaces from the array (byte values of 255).
I've tried setting the padding to none but it doesn't work. As long as the
array doesn't have any white spaces in there it encrypts and decrypts
normally.

Anyone have any ideas on how to fix this?


Could you show us some code (ideally, the smallest example that goes
wrong)? I just knocked this together and it performs as expected:
Imports System.Security .Cryptography
Imports System.Text
Imports System.IO

Module Module1

Sub Main()

Dim plaintext() As Byte = New Byte() {&H12, &H34, &H56, &H78,
&HFF, &H9A, &HFF, &HBC, &HFF, &HDE}

Console.Write(" starting plaintext: ")
Console.WriteLi ne(OutHex(plain text))

Dim algo As SymmetricAlgori thm = RijndaelManaged .Create
algo.GenerateKe y()
algo.GenerateIV ()
Dim key() As Byte = algo.Key
Dim iv() As Byte = algo.IV

Dim encryptor As ICryptoTransfor m = algo.CreateEncr yptor
Dim encr() As Byte = encryptor.Trans formFinalBlock( plaintext,
0, plaintext.Lengt h)

Console.Write(" encrypted : ")
Console.WriteLi ne(OutHex(encr) )

Dim decryptor As ICryptoTransfor m = algo.CreateDecr yptor
Dim decr() As Byte = decryptor.Trans formFinalBlock( encr, 0,
encr.Length)

Console.Write(" decrypted : ")
Console.WriteLi ne(OutHex(decr) )

Console.ReadLin e()
End Sub

Private Function OutHex(ByVal arr() As Byte) As String
Dim out As New StringBuilder(a rr.Length * 3)

For index As Integer = 0 To arr.Length - 1
out.Append(arr( index).ToString ("X").PadLeft(2 , "0"c))
out.Append(" ")
Next

Return out.ToString
End Function

End Module

Output is:

starting plaintext: 12 34 56 78 FF 9A FF BC FF DE
encrypted : EF 64 FA 6A 2E A9 1F 29 9A 01 4C E4 4D 80 77 0A
decrypted : 12 34 56 78 FF 9A FF BC FF DE

As I would expect, there isn't any special treatment for bytes holding
255.

--
Larry Lard
Replies to group please

Jun 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1890
by: Stu | last post by:
Hi, Im reading a file in from disk as a byte array then passing it to a memory stream for decryption using crypto api functions. What I have found is that you need to reduce the array length by 2 from the original lenght in order to get it to work as there seems to be 2 extra 0 bytes at the end. Functions included Stu
8
14275
by: Peter O'Reilly | last post by:
I have an HTML form with a textarea input box. When the user conducts a post request (e.g. clicks the submit button), an HTML preview page is presented to them with the information they have filled out in the prior page's form elements. Naturally some users like to copy and paste text into the textarea box and presumably do so from say a word processor program. Some Macintosh based users I know of experience problems with foreign...
2
3792
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short- cut solution for finding collisions in SHA-1 . Their result
5
36887
by: Jonathan Ng | last post by:
Hi, I was wondering if there was a way to include the white spaces in a string. Currently, I am using: scanf("%s", &input); However, this doesn't include the 'space' character or any other white spaces. Is there a way I can include the 'space' character rather than skip in.
11
15019
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white spaces(if it more than once between two words). Is there any function we have in C which will find out the tabs and white spaces and returns the text in the follwong way -
0
4710
by: Cory Baker | last post by:
Hi all! I am trying to encrypt data with C# and decrypt the same data using VC++ 6, both using a password. I believe that I am very close on this one but am currently stuck and am receiving error 2148073477 on the VC++ CryptDecrypt() call. My keys generated by C# and VC++ are the same, so that seems to be okay. My C# code is as follows:
2
1923
by: Mark | last post by:
I have been playing around with encrypting passwords using a class found in a MS KB (see farther down). It seems to work great so long as the original password is comprised of characters on the keyboard. However, if the password is mixed with characters in both ASCII code set 0-127 and 128-255, I run into a problem. Users can set a password using keyboard characters and by holding ALT and typing in the decimal value for the non-keyboard...
6
1818
by: SenseiHitokiri | last post by:
I have some code that converts a string into base64 for some encryption. It was written on the 1.1 framework but I am trying to get it to work on 2.0. It throws exceptions on the cryptStream.FlushFinalBlock() and cryptStream.Clear(). Can anyone tell me what is up with this? Thanks ahead of time for any help you can offer. public static string EncryptAndBase64( string val ) { byte buf = UnicodeEncoding.Unicode.GetBytes(val);
3
1919
by: ayan4u | last post by:
well i need to deal with white spaces in charecter arrays... with static arrays its fine.. char ss; cin.getline(ss, sizeof ss); .... //deals with white spaces
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.