473,791 Members | 2,816 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 9208

"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
11739
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
26798
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
4285
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
4591
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
933
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
8040
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
2559
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
1377
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
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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
10426
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
9993
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
9029
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
6776
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
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.