473,804 Members | 3,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DESCryptoServic eProvider used to encrypt a 64 length string, funny output

When I run the below method with a 64 character string as input such
as:

sr.Encrypt("123 456789012345678 901234567890123 456789012345678 901234567890444 4");

I get square boxes as my output, which means that some characters are
not being mapped in the encodings. What could be the problem?

Since my output is funny characters, my decrption will as a result
fail since it contiains invalid characters when I do a
FromBase64Strin g.

TIA
(Code Below)
*************** *************** *************** ********
public string TestEncrypt(str ing StrintToEncrpt)
{
string strOutput;

UTF8Encoding uTF8Encoding = new UTF8Encoding();
DESCryptoServic eProvider dESCryptoServic eProvider = new
DESCryptoServic eProvider();

dESCryptoServic eProvider.Key = uTF8Encoding.Ge tBytes("1234567 8");
dESCryptoServic eProvider.IV = dESCryptoServic eProvider.Key;

ICryptoTransfor m iCryptoTransfor m =
dESCryptoServic eProvider.Creat eEncryptor();

byte[] byte1 = Convert.FromBas e64String(Strin tToEncrpt);

byte[] byte2 = iCryptoTransfor m.TransformFina lBlock(byte1, 0,
byte1.GetLength (0));

strOutput = Encoding.ASCII. GetString(byte2 );
return strOutput;
}

http://www.csharpfriends.com
~Salman
Nov 15 '05 #1
2 9209

"Salman" <ad***@csharpfr iends.com> wrote in message
news:f6******** *************** **@posting.goog le.com...
When I run the below method with a 64 character string as input such
as:

sr.Encrypt("123 456789012345678 901234567890123 456789012345678 901234567890444 4
");
I get square boxes as my output, which means that some characters are
not being mapped in the encodings. What could be the problem?

Since my output is funny characters, my decrption will as a result
fail since it contiains invalid characters when I do a
FromBase64Strin g.

TIA
(Code Below)
*************** *************** *************** ********
public string TestEncrypt(str ing StrintToEncrpt)
{
string strOutput;

UTF8Encoding uTF8Encoding = new UTF8Encoding();
DESCryptoServic eProvider dESCryptoServic eProvider = new
DESCryptoServic eProvider();

dESCryptoServic eProvider.Key = uTF8Encoding.Ge tBytes("1234567 8");
dESCryptoServic eProvider.IV = dESCryptoServic eProvider.Key;

ICryptoTransfor m iCryptoTransfor m =
dESCryptoServic eProvider.Creat eEncryptor();

byte[] byte1 = Convert.FromBas e64String(Strin tToEncrpt);

byte[] byte2 = iCryptoTransfor m.TransformFina lBlock(byte1, 0,
byte1.GetLength (0));

strOutput = Encoding.ASCII. GetString(byte2 );
return strOutput;
}

http://www.csharpfriends.com
~Salman


You're trying to convert your byte2 array into ASCII even though it contains
non-ASCII code values. If you want to store the output of an arbitrary array
of bytes as an ASCII string you'll need to use Convert.ToBase6 4String() or
some other method.
Nov 15 '05 #2

"Salman" <ad***@csharpfr iends.com> wrote in message
news:f6******** *************** **@posting.goog le.com...
When I run the below method with a 64 character string as input such
as:

sr.Encrypt("123 456789012345678 901234567890123 456789012345678 901234567890444 4
");
I get square boxes as my output, which means that some characters are
not being mapped in the encodings. What could be the problem?

Since my output is funny characters, my decrption will as a result
fail since it contiains invalid characters when I do a
FromBase64Strin g.

TIA
(Code Below)
*************** *************** *************** ********
public string TestEncrypt(str ing StrintToEncrpt)
{
string strOutput;

UTF8Encoding uTF8Encoding = new UTF8Encoding();
DESCryptoServic eProvider dESCryptoServic eProvider = new
DESCryptoServic eProvider();

dESCryptoServic eProvider.Key = uTF8Encoding.Ge tBytes("1234567 8");
dESCryptoServic eProvider.IV = dESCryptoServic eProvider.Key;

ICryptoTransfor m iCryptoTransfor m =
dESCryptoServic eProvider.Creat eEncryptor();

byte[] byte1 = Convert.FromBas e64String(Strin tToEncrpt);

byte[] byte2 = iCryptoTransfor m.TransformFina lBlock(byte1, 0,
byte1.GetLength (0));

strOutput = Encoding.ASCII. GetString(byte2 );
return strOutput;
}

http://www.csharpfriends.com
~Salman


You're trying to convert your byte2 array into ASCII even though it contains
non-ASCII code values. If you want to store the output of an arbitrary array
of bytes as an ASCII string you'll need to use Convert.ToBase6 4String() or
some other method.
Nov 15 '05 #3

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

Similar topics

5
11743
by: MLH | last post by:
I'm working with lots of long strings now, it seems. I have to import them & parse them constantly. The A97 memo field type supports only 32768 chars. What happens when this is processed... Dim MyString As String Am I getting VLS declaration or a FLS declaration? Can I control which I get somehow? I have done some homework, but I don't understand
0
337
by: Salman | last post by:
When I run the below method with a 64 character string as input such as: sr.Encrypt("1234567890123456789012345678901234567890123456789012345678904444"); I get square boxes as my output, which means that some characters are not being mapped in the encodings. What could be the problem? Since my output is funny characters, my decrption will as a result fail since it contiains invalid characters when I do a
7
26799
by: Matthias S. | last post by:
Hi, I had a look at the vast information on encryption in the MSDN and got pretty confused. All I want to do is to encrypt a string into an encrypted string and later decrypt that (encrypted) string again to a human readable form. Can't be that difficult :). Could you send me please into the right direction. Thanks in advance. --
8
4287
by: toupeira23 | last post by:
Hello, I'm trying to encrypt passwords in my app. After discovering that there's no simple function to do this, I wrote a wrapper class which decodes a string using UTF8, encrypts it with TripleDES and returns a Base64-encoded string. The decryption function does the reverse, i.e. Base64-decodes the string, decrypts it with the same Key and IV, and encodes it again with UTF8. The problem is that after decrypting, the 8th character is...
10
4593
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a zero-length string (always returns a zero-length string when used in a query expression)" **** How many records are there in FirstTable in which Product Is Null. SELECT COUNT(*) AS CountofNullProdcut
1
934
by: Jon Paal | last post by:
need help with code to encrypt a string and write it out to a file. code does not write out to file =========code============== Private Shared ReadOnly encryptionKeyBytes() As Byte = New Byte() {53, 53, 53, 53, 53, 53, 53, 53} Private Shared Function GenerateEncryptedLicFile(ByVal inputText As String, ByVal outputFile As String) As Boolean Dim outputStream As Stream = Nothing Dim encryptedStream As Stream = Nothing
1
8041
by: Sathyaish | last post by:
I have the following scenario: Algorithm: 3DES Cipher Mode: CBC Key Size: 128-bit Block Size: 64 bit IV: 0x0000000000000000 (an eight byte array of zeros) The results I get using .NET with the following routine are:
6
2560
by: nickyeng | last post by:
i have a midlet which will generate a string (message ) and send to our gateway. but before sending, i will need to encrypt the string. i've checked anywhere in internet but couldn't find j2me API about encryption. what is the simple way to encrypt that string in midlet ? anyone idea?
1
1378
Prakash Gnana
by: Prakash Gnana | last post by:
Is it possible to encrypt a string in php? Is yes, then how to encrypt a string in php?
0
9572
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
10562
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
10070
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
9132
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...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
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
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
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.