I'm trying to figure out how to remove the characters padded to the end of
my string without setting the Padding = PaddingMode.Non e.
My original string passed in is 'passwordTest' and the resulting decrypted
string is 'passwordTestAA AAAAAAAA=='
I would like to use for both strings and files.
private static string DoEncryption(by te []data)
{
DES des = new DESCryptoServic eProvider();
des.Key = key;
des.IV = des.Key;
des.Padding = PaddingMode.PKC S7;
System.IO.Memor yStream ms = new System.IO.Memor yStream();
ICryptoTransfor m desencrypt = des.CreateEncry ptor();
CryptoStream stream = new CryptoStream(ms , desencrypt,
CryptoStreamMod e.Write);
stream.Write(da ta, 0, data.Length);
stream.FlushFin alBlock();
ms.Position = 0;
string encrypted = string.Empty;
encrypted = Convert.ToBase6 4String(ms.ToAr ray() );
stream.Close();
return encrypted;
}
private static string DoDecryption(by te []data)
{
DES des = new DESCryptoServic eProvider();
des.Key = key;
des.IV = des.Key;
des.Padding = PaddingMode.PKC S7;
System.IO.Memor yStream ms = new System.IO.Memor yStream(data);
CryptoStream stream = new CryptoStream(ms , des.CreateDecry ptor(),
CryptoStreamMod e.Read);
byte []fromEncrypt = new byte[data.Length];
stream.Read(fro mEncrypt, 0, fromEncrypt.Len gth);
stream.Close();
return Convert.ToBase6 4String(fromEnc rypt);
}
}
Thanks,
Joe 5 9014
Joe wrote: I'm trying to figure out how to remove the characters padded to the end of my string without setting the Padding = PaddingMode.Non e.
.....
Joe,
You'll need to know what bytes are the Pad characters, and also
calcualate how many bytes will be padded based on the block size of your
cipher. i.e. If block length is 64 bits and last block is 40 bits, 24
bits will be padded.
I wouldn't reccomend using a block cipher for encrypting strings though
as block ciphers are just good for encrypting large chunks of data i.e.
files. For strings, I would encrourage a stream cipher, where you wont
have to deal with leftover bytes.
--
Rob Schieber
Thanks Rob. Do you know of an example of a stream cipher?
"Rob Schieber" <sc******@hotma il.com> wrote in message
news:eL******** ******@TK2MSFTN GP10.phx.gbl... Joe wrote: I'm trying to figure out how to remove the characters padded to the end of my string without setting the Padding = PaddingMode.Non e. ....
Joe,
You'll need to know what bytes are the Pad characters, and also calcualate how many bytes will be padded based on the block size of your cipher. i.e. If block length is 64 bits and last block is 40 bits, 24 bits will be padded.
I wouldn't reccomend using a block cipher for encrypting strings though as block ciphers are just good for encrypting large chunks of data i.e. files. For strings, I would encrourage a stream cipher, where you wont have to deal with leftover bytes.
-- Rob Schieber
Joe wrote: Thanks Rob. Do you know of an example of a stream cipher?
"Rob Schieber" <sc******@hotma il.com> wrote in message news:eL******** ******@TK2MSFTN GP10.phx.gbl...
Joe wrote:
I'm trying to figure out how to remove the characters padded to the end of my string without setting the Padding = PaddingMode.Non e.
....
Joe,
You'll need to know what bytes are the Pad characters, and also calcualate how many bytes will be padded based on the block size of your cipher. i.e. If block length is 64 bits and last block is 40 bits, 24 bits will be padded.
I wouldn't reccomend using a block cipher for encrypting strings though as block ciphers are just good for encrypting large chunks of data i.e. files. For strings, I would encrourage a stream cipher, where you wont have to deal with leftover bytes.
-- Rob Schieber
Interestingly, it doesn't look like the .net framework exposes stream
ciphers. Not sure why that is. I think I should clarify myself though,
theres nothing wrong with using block ciphers to encrypt strings/text,
its just that stream ciphers tend to be a little faster at the expense
of a little less security.
Theres a decent example of using RC4 with c#, which is a stream cipher,
here... http://www.codeproject.com/csharp/rc4csharp.asp.
Hope that helps.
--
Rob Schieber
Rob,
I'm a little confused about your suggestion on figuring out the block
length. If I don't know the original string that was encrypted, how can I
figure this out?
-Joe
"Rob Schieber" <sc******@hotma il.com> wrote in message
news:eL******** ******@TK2MSFTN GP10.phx.gbl... Joe wrote: I'm trying to figure out how to remove the characters padded to the end of my string without setting the Padding = PaddingMode.Non e. ....
Joe,
You'll need to know what bytes are the Pad characters, and also calcualate how many bytes will be padded based on the block size of your cipher. i.e. If block length is 64 bits and last block is 40 bits, 24 bits will be padded.
I wouldn't reccomend using a block cipher for encrypting strings though as block ciphers are just good for encrypting large chunks of data i.e. files. For strings, I would encrourage a stream cipher, where you wont have to deal with leftover bytes.
-- Rob Schieber
Joe wrote: I'm trying to figure out how to remove the characters padded to the end of my string without setting the Padding = PaddingMode.Non e.
Why? what's wrong with the padding?
I doubt that the code you have sent is the code you tested:
- there are references to "key" which is not in scope
- the encryption returns a string but the decryption accepts byte[]
- the Base64 decoding for decryption is done *after* decryption...
I posted some comments and an example on how to do simple encryption in
a secure way a few weeks ago, Message-ID:
<#r************ **@TK2MSFTNGP12 .phx.gbl> in the thread "Encrypt and
Decrypt in C#".
--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
by: JW |
last post by:
I can encrypt the contents of a memory stream with no problems, however when
decrypting( I'm using the same key an IV ) I get an exception stating bad
data.
I'm at a lost. I'm actually creating a new memory stream, filling it with
the encrypted bytes then trying to read from the crypto stream object. I
have used the same approach encrypting to a file handle and then decrypting
from the same file and it works.
|
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
|
by: Tom |
last post by:
Hi experts,
I have the following code, which works fine:
######################### C# snippet
########################################
string k = "12345678";
string input = "ABCDEFGH";
DES des_dec = new DESCryptoServiceProvider();
|
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 = System.Text.Encoding.Unicode.GetBytes(text);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Key = this.key;
des.IV = this.iv;
| |
by: PaulN |
last post by:
I'm working on an inherited app that decrypts an XML file ftp'd from a
web site and then fills a dataset with it and then loads it into a
database.
The app as written decrypts the xml into a second plain ASCII xml and
writes the file to disk and then loads that file eventually into the
database.
I really don't want 2 files hanging around. I've been trying to decrypt
to a memory stream object and load that into the dataset, but without
|
by: Sam |
last post by:
Hi,
I have a bunch of xml files that are used by my vb application. Those
files were written by hand (ie not generated). Do you know a tool to
encrypt them, so that no one can read their content when opening them,
which would also allow me to decrypt them in my code via some
functions?
Thx
|
by: Harb247 |
last post by:
Hi Guys,
First Post. Need some help decrypting a String / DB
The company i manage recently had an argument with their lead programmer for their data base. However he has decided to have nothing to do with the company so i cannot contact him to get the info i require.
Ive looked over his computer and accessed the .dat (I have no idea why its a .dat file) file using the password however when i open it up in Access i can view the data with...
|
by: Fritjolf |
last post by:
Hi.
I've got a strange problem...
I've made a simple program to test encryption/decryption.
I use Rijndael encryption and here are the most important properties.
RijndaelManaged cipher = new RijndaelManaged();
cipher.KeySize = 256;
cipher.BlockSize = 256;
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |