473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DESCryptoServiceProvider

Hello,

would you please provide me with some simple sample of how to use the
DESCryptoServiceProvider to encrypt a buffer

byte[] buffer;

with key

byte[] key;

produceing cipher text:

byte[] ciphertext;

I saw some sample using Streams, but is there a simpler method working for
buffers?

O.

Jul 21 '05 #1
1 3005
<"Ondrej Sevecek" <ondra_at_sevecek_dt_com>> wrote:
Hello,

would you please provide me with some simple sample of how to use the
DESCryptoServiceProvider to encrypt a buffer

byte[] buffer;

with key

byte[] key;

produceing cipher text:

byte[] ciphertext;

I saw some sample using Streams, but is there a simpler method working for
buffers?


You need to use a stream at some stage, but using MemoryStream and its
ToArray method make it easy to return a byte array.

Basically, just create a MemoryStream, then an appropriate CryptoStream
to write into that. Write your original buffer into the CryptoStream,
close it (which will do the appropriate FlushFinalBlock - just
disposing of it won't, due to a bug in 1.1), and then call ToArray on
the MemoryStream.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

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

Similar topics

2
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...
2
by: Tom | last post by:
Hi experts, I have the following code, which works fine: ######################### C# snippet ######################################## string k = "12345678"; string input = "ABCDEFGH"; ...
3
by: wolf | last post by:
Can I de-crypt the data by java which is crypt by DESCryptoServiceProvider? The following is my code to crypt data: string text = "This is My source data"; byte source =...
8
by: Gidi | last post by:
Hi, Is there Buid-In fuction in C# that Encrypt and Decrypt strings? i have a textbox which i'm writing into file, and i want to encrypt it before writing, i'm not looking for something fancy,...
5
by: Joe | last post by:
I'm trying to figure out how to remove the characters padded to the end of my string without setting the Padding = PaddingMode.None. My original string passed in is 'passwordTest' and the...
5
by: Sia Jai Sung | last post by:
Hi, I have a class that I modify from a sample program, like below ========================================== Imports System Imports System.Web.UI Imports System.Security.Cryptography ...
1
by: Ondrej Sevecek | last post by:
Hello, would you please provide me with some simple sample of how to use the DESCryptoServiceProvider to encrypt a buffer byte buffer; with key byte key;
4
by: Andreas Pauley | last post by:
Hi all, I'm trying to implement a Python equivalent of a C# method that encrypts a string. My Python attempt is in the attached file, but does not return the same value as the C# method (see...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.