473,699 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Encryption and Decryption

Hi,
I would like to enrypt and decrypt a simple line of text, with a
private(symmetr ic) key.

I have tried searching in the System.Cryptogr aphy class, but I can't
find a simple way of doing this job.

Can someone recommend me an easy way on how to do it.
Thanks in Advance
Nov 16 '05 #1
14 6566
"Xarky" <be*********@ya hoo.com> wrote in message
news:bc******** *************** **@posting.goog le.com...
Hi,
I would like to enrypt and decrypt a simple line of text, with a
private(symmetr ic) key.

I have tried searching in the System.Cryptogr aphy class, but I can't
find a simple way of doing this job.

Can someone recommend me an easy way on how to do it.
Thanks in Advance


There is a Microsoft way to do this. However you can also do it
naively, since every character is representable by an ascii number,
your line of text evaluates to a line of numbers, on which you can
let loose some algorithm to scramble it.
Nov 16 '05 #2
Zach <wa**********@a ll.here> wrote:
"Xarky" <be*********@ya hoo.com> wrote in message
news:bc******** *************** **@posting.goog le.com...
Hi,
I would like to enrypt and decrypt a simple line of text, with a
private(symmetr ic) key.

I have tried searching in the System.Cryptogr aphy class, but I can't
find a simple way of doing this job.

Can someone recommend me an easy way on how to do it.
Thanks in Advance


There is a Microsoft way to do this. However you can also do it
naively, since every character is representable by an ascii number,
your line of text evaluates to a line of numbers, on which you can
let loose some algorithm to scramble it.


No, *not* every character is representable by an ascii number. ASCII
has no Unicode values over 127, whereas there are *loads* of Unicode
characters over 127...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Zach <wa**********@a ll.here> wrote:
"Xarky" <be*********@ya hoo.com> wrote in message
news:bc******** *************** **@posting.goog le.com...
Hi,
I would like to enrypt and decrypt a simple line of text, with a
private(symmetr ic) key.

I have tried searching in the System.Cryptogr aphy class, but I can't
find a simple way of doing this job.

Can someone recommend me an easy way on how to do it.
Thanks in Advance


There is a Microsoft way to do this. However you can also do it
naively, since every character is representable by an ascii number,
your line of text evaluates to a line of numbers, on which you can
let loose some algorithm to scramble it.


No, *not* every character is representable by an ascii number. ASCII
has no Unicode values over 127, whereas there are *loads* of Unicode
characters over 127...


Oh dear, the OP is talking about "a simple line of text".
Nov 16 '05 #4
Xarky,

Check out any of the classes that derive from
System.Security .Cryptography.S ymmetricAlgorit hm.

Regards,
Joakim

Xarky wrote:
Hi,
I would like to enrypt and decrypt a simple line of text, with a
private(symmetr ic) key.

I have tried searching in the System.Cryptogr aphy class, but I can't
find a simple way of doing this job.

Can someone recommend me an easy way on how to do it.
Thanks in Advance

Nov 16 '05 #5
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Zach <wa**********@a ll.here> wrote:
"Xarky" <be*********@ya hoo.com> wrote in message
news:bc******** *************** **@posting.goog le.com...
Hi,
I would like to enrypt and decrypt a simple line of text, with a
private(symmetr ic) key.

I have tried searching in the System.Cryptogr aphy class, but I can't
find a simple way of doing this job.

Can someone recommend me an easy way on how to do it.
Thanks in Advance


There is a Microsoft way to do this. However you can also do it
naively, since every character is representable by an ascii number,
your line of text evaluates to a line of numbers, on which you can
let loose some algorithm to scramble it.


No, *not* every character is representable by an ascii number. ASCII
has no Unicode values over 127, whereas there are *loads* of Unicode
characters over 127...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


If thew OPs line of text is in Unified Canadian Aboriginal Syllabics
this is where he will find the unicode
http://www.geocities.com/Athens/Acad.../fontset.htm#a

Nov 16 '05 #6
Zach <wa**********@a ll.here> wrote:
No, *not* every character is representable by an ascii number. ASCII
has no Unicode values over 127, whereas there are *loads* of Unicode
characters over 127...


Oh dear, the OP is talking about "a simple line of text".


So are you 100% positive that a "simple line of text" can't contain any
non-ASCII characters? That's a view which is very much biased towards
the English-speaking world.

Basically, assuming that ASCII is good enough for text files is a
recipe for disaster unless you have specifications which you can
guarantee won't change to allow "real" text. (It's usually good enough
for header names, but not always header values, for instance.)

There are perfectly good ways of encrypting text without making such
assumptions - just using UTF-8 instead of ASCII to convert the text
data into binary data would be my suggestion.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
I have written an article that may help you:

http://www.dalepreston.com/Blog/Arch...0_Archive.html

DalePres
MCAD, MCDBA, MCSE

"Xarky" <be*********@ya hoo.com> wrote in message
news:bc******** *************** **@posting.goog le.com...
Hi,
I would like to enrypt and decrypt a simple line of text, with a
private(symmetr ic) key.

I have tried searching in the System.Cryptogr aphy class, but I can't
find a simple way of doing this job.

Can someone recommend me an easy way on how to do it.
Thanks in Advance

Nov 16 '05 #8
DalePres <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote:
I have written an article that may help you:

http://www.dalepreston.com/Blog/Arch...0_Archive.html


Unfortunately that makes the same mistake that Zach did - assuming that
all text is ASCII.

I suggest using UTF-8 instead. Just use Encoding.UTF8.G etBytes instead
of Encoding.ASCII. (I'm also not sure why you're using Encoding.ASCII
in one place and manually creating an instance of ASCIIEncoding in
another.)

Also note that the call to Substring at the end isn't required if you
do things properly - don't assume that the decrypted data is the same
length as the encrypted data, but read the whole of the stream instead.
(Also don't assume that a single call to Stream.Read will do everything
you want it to. See http://www.pobox.com/~skeet/csharp/readbinary.html
for more on this.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9
Thanks for the good ideas.

DalePres

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
DalePres <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote:
I have written an article that may help you:

http://www.dalepreston.com/Blog/Arch...0_Archive.html


Unfortunately that makes the same mistake that Zach did - assuming that
all text is ASCII.

I suggest using UTF-8 instead. Just use Encoding.UTF8.G etBytes instead
of Encoding.ASCII. (I'm also not sure why you're using Encoding.ASCII
in one place and manually creating an instance of ASCIIEncoding in
another.)

Also note that the call to Substring at the end isn't required if you
do things properly - don't assume that the decrypted data is the same
length as the encrypted data, but read the whole of the stream instead.
(Also don't assume that a single call to Stream.Read will do everything
you want it to. See http://www.pobox.com/~skeet/csharp/readbinary.html
for more on this.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #10

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

Similar topics

1
2419
by: D. Alvarado | last post by:
On my Fedora Core 2 Linux dev box, I have installed mcrypt and compiled PHP with the --with-mcrypt option. I am concerned that when I move to another hosting enviornment mcrypt will not be supported. In people's experiences, have hosting companies supporting PHP/MySQL generally provided support for mcrypt? Does anyone recommend another module for encryption/decryption that accompanies the PHP package? Thanks, - Dave
1
2464
by: Jase H | last post by:
Hello, I have a ASP.NET web application problem involving the data encryption and decryption assembly(DLL) used on the connection string value that is set in the webconfig file. The problem occurs in the application when you instantiate a new instance of the class as shown below: ---Dim dp As DPAPIComp.DataProtectorComp = New DPAPIComp.DataProtectorComp--- where DPAPIComp is the name of the namespace referenced to in the library
2
4194
by: Dave Bailey | last post by:
I have developed a web app using DPAPI to encrypt a connection string in the web.config file. The application works perfectly on the development machine but when deployed to the server when opening the app the following wrror is generated: Exception decrypting. Decryption failed. Key not valid for use in specified state. Description: An unhandled exception occurred during the execution of the current web request. Please review the
2
2578
by: sushant.bhatia | last post by:
Hi All. I'm using the NCrypto dll for RSA Encryption/Decryption (http://sourceforge.net/projects/ncrypto/). My encryption code in .Net is pretty simple. The dataToEncrypt length is 1024. The returned data is 1161 in length. public static byte EncryptRSA(string certFilePublic, byte dataToEncrypt) { RSAParameters rsaParams = GetRSAPubKey(certFilePublic);
3
2302
by: Mike | last post by:
Hi, I have been experimenting with the RijndaelManaged Cryptography class in C# and have stumbled upon a "peculiarity". Following code is standalone Console App that demonstrates using System; using System.Text; using System.IO;
2
7145
by: almurph | last post by:
Hi everyone, Can you help me please? I am having a problem with the encryption/decryption of words with the Irish fada in them. The Irish fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the French grave... Anyway when I run encryption on a plaintext word like:
3
3068
by: =?Utf-8?B?TG9yZW4=?= | last post by:
I’m trying to encrypt and decrypt a file in vb.net. I am using the TripleDESCryptoServiceProvider encryption found in System.Security.Cryptography. Below is the code for my Encrypt and Decrypt functions. While my functions read and write files the encryption/decryption is not working properly. My test file has an original length of 66,048 bytes. My encrypted file ends up with 66,056 bytes … 8 bytes more than my original. When I...
5
9514
by: Netwatcher | last post by:
well, i started messing around with dictionaries, yet, most of the pages i found about them always talk about getting only one word out of it and turning it vice versa, i've been playing with that code for a few hours: #dics Encryption={',':'hy{;',' ':'h4x0r2','':'zomg','?':'bko','a':'ika','b':'d0v','c':'ino', 'd':'maw', 'e':'aon', 'f':'que', 'g':'kip', 'h':'an', 'n':'ko print lol except KeyError: print 'These...
9
4813
by: Betikci Boris | last post by:
I get bored last night and wrote a script that uses xor for encrypt- decrypt, however it woks fine under linux 2.6.25, text and documents are ok, but fails on compressed files *.jpg, *.pdf , etc . I didn't test script on windows. Here is the code, please send me your views. <?php /* Mother Eye Chipper with PHP :), Licence:GPL,
9
2438
by: Alan M Dunsmuir | last post by:
In my (PHP-5) application I have to write some records to a table in my database, which I don't want even my clients using the system to be able to read. This is not a problem in National Security; I simply want the contents of records in this file to remain unreadable, even by the client's IT supervisor who can look at the contents of the (MySQL) database using phpMyAdmin. I intend, periodically, to download these records to my local...
0
8685
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
8612
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
9032
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
8905
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
8880
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
5869
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
4373
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
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2008
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.