473,466 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DES Crypto not working ???

Hi. I have the following simple code, and yet.... I enter for instance
"Encryption" and I get back ">ZH(5f^0"

Web.Config:
---------------------------------------------------------------------
<appSettings>
<add key="DESKey" value="MAMMAMIA"></add>
<add key="DESIV" value="PAPPAPIA"></add>
</appSettings>
---------------------------------------------------------------------

Module Utils:
---------------------------------------------------------------------
Imports System.IO
Namespace Raducu
Module Utils

Public Function ConvertToByteArray(ByVal strInput As String) As
Byte()
Dim intCounter As Integer
Dim arrChar As Char()
Dim arrByte As Byte()

arrChar = strInput.ToCharArray
ReDim arrByte(arrChar.Length - 1)
For intCounter = 0 To arrByte.Length - 1
arrByte(intCounter) = Convert.ToByte(arrChar(intCounter))
Next
Return arrByte
End Function

Public Function FileExists(ByVal strPath As String) As Boolean
Return File.Exists(strPath)
End Function

End Module
End Namespace
---------------------------------------------------------------------

and in the form:
---------------------------------------------------------------------
Imports System.Security.Cryptography
Imports System.IO

Public Class Encrypt_Decrypt
Inherits System.Web.UI.Page

Protected WithEvents txtEncrypt As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdEncrypt As System.Web.UI.WebControls.Button
Protected WithEvents txtDecrypt As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdDecrypt As System.Web.UI.WebControls.Button
Protected WithEvents lblResults As System.Web.UI.WebControls.Label

Private Sub cmdEncrypt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEncrypt.Click

Dim strInput As String
Dim arrDESKey As Byte()
Dim arrDESIV As Byte()
Dim arrInput As Byte()
Dim objFileStream As FileStream
Dim objDES As DESCryptoServiceProvider
Dim objEncryptor As ICryptoTransform
Dim objCryptoStream As CryptoStream

Try
strInput = txtEncrypt.Text
If strInput <> "" Then
arrInput = Raducu.Utils.ConvertToByteArray(strInput)
arrDESKey =
Raducu.Utils.ConvertToByteArray(ConfigurationSetti ngs.AppSettings("DESKey"))
arrDESIV =
Raducu.Utils.ConvertToByteArray(ConfigurationSetti ngs.AppSettings("DESIV"))
objDES = New DESCryptoServiceProvider()
objEncryptor = objDES.CreateEncryptor(arrDESKey, arrDESIV)
objFileStream = New FileStream(MapPath("Secret.txt"),
FileMode.Create, FileAccess.Write)
objCryptoStream = New CryptoStream(objFileStream,
objEncryptor, CryptoStreamMode.Write)
objCryptoStream.Write(arrInput, 0, arrInput.Length)
objCryptoStream.Close()
objFileStream.Close()
End If
Catch ex As Exception
lblResults.Text &= "<li>" & ex.ToString
Finally
objEncryptor.Dispose()
End Try
End Sub

Private Sub cmdDecrypt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDecrypt.Click

Dim arrDESKey As Byte()
Dim arrDESIV As Byte()
Dim objFileStream As FileStream
Dim objDES As DESCryptoServiceProvider
Dim objDecryptor As ICryptoTransform
Dim objCryptoStream As CryptoStream

If Raducu.Utils.FileExists(MapPath("Secret.txt")) Then
Try
arrDESKey =
Raducu.Utils.ConvertToByteArray(ConfigurationSetti ngs.AppSettings("DESKey"))
arrDESIV =
Raducu.Utils.ConvertToByteArray(ConfigurationSetti ngs.AppSettings("DESIV"))
objDES = New DESCryptoServiceProvider()
objDecryptor = objDES.CreateEncryptor(arrDESKey, arrDESIV)
objFileStream = New FileStream(MapPath("Secret.txt"),
FileMode.Open, FileAccess.Read)
objCryptoStream = New CryptoStream(objFileStream,
objDecryptor, CryptoStreamMode.Read)
txtDecrypt.Text = New
StreamReader(objCryptoStream).ReadToEnd
objCryptoStream.Close()
objFileStream.Close()
Catch ex As Exception
lblResults.Text &= "<li>" & ex.ToString
Finally
objDecryptor.Dispose()
End Try
Else
lblResults.Text &= "<li>" & "The file '" & MapPath("Secret.txt")
& " does not exist !"
End If
End Sub
End Class
---------------------------------------------------------------------

Please, could you tell me where is my problem ? The code looks fine to me...

Thank you, Alex.
Nov 19 '05 #1
1 1323
you may take a look at:
www.aspsimply.com/aspnet/CryptoASPX.aspx
www.aspsimply.com/vbnet/ProTool.aspx

regards
"Alex Nitulescu" <RE***********************@yahoo.com> wrote in message
news:eZ**************@TK2MSFTNGP14.phx.gbl...
Hi. I have the following simple code, and yet.... I enter for instance
"Encryption" and I get back ">ZH(5f^0"

Web.Config:
---------------------------------------------------------------------
<appSettings>
<add key="DESKey" value="MAMMAMIA"></add>
<add key="DESIV" value="PAPPAPIA"></add>
</appSettings>
---------------------------------------------------------------------

Module Utils:
---------------------------------------------------------------------
Imports System.IO
Namespace Raducu
Module Utils

Public Function ConvertToByteArray(ByVal strInput As String) As
Byte()
Dim intCounter As Integer
Dim arrChar As Char()
Dim arrByte As Byte()

arrChar = strInput.ToCharArray
ReDim arrByte(arrChar.Length - 1)
For intCounter = 0 To arrByte.Length - 1
arrByte(intCounter) = Convert.ToByte(arrChar(intCounter))
Next
Return arrByte
End Function

Public Function FileExists(ByVal strPath As String) As Boolean
Return File.Exists(strPath)
End Function

End Module
End Namespace
---------------------------------------------------------------------

and in the form:
---------------------------------------------------------------------
Imports System.Security.Cryptography
Imports System.IO

Public Class Encrypt_Decrypt
Inherits System.Web.UI.Page

Protected WithEvents txtEncrypt As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdEncrypt As System.Web.UI.WebControls.Button
Protected WithEvents txtDecrypt As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdDecrypt As System.Web.UI.WebControls.Button
Protected WithEvents lblResults As System.Web.UI.WebControls.Label

Private Sub cmdEncrypt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdEncrypt.Click

Dim strInput As String
Dim arrDESKey As Byte()
Dim arrDESIV As Byte()
Dim arrInput As Byte()
Dim objFileStream As FileStream
Dim objDES As DESCryptoServiceProvider
Dim objEncryptor As ICryptoTransform
Dim objCryptoStream As CryptoStream

Try
strInput = txtEncrypt.Text
If strInput <> "" Then
arrInput = Raducu.Utils.ConvertToByteArray(strInput)
arrDESKey =
Raducu.Utils.ConvertToByteArray(ConfigurationSetti ngs.AppSettings("DESKey"))
arrDESIV =
Raducu.Utils.ConvertToByteArray(ConfigurationSetti ngs.AppSettings("DESIV"))
objDES = New DESCryptoServiceProvider()
objEncryptor = objDES.CreateEncryptor(arrDESKey, arrDESIV)
objFileStream = New FileStream(MapPath("Secret.txt"),
FileMode.Create, FileAccess.Write)
objCryptoStream = New CryptoStream(objFileStream,
objEncryptor, CryptoStreamMode.Write)
objCryptoStream.Write(arrInput, 0, arrInput.Length)
objCryptoStream.Close()
objFileStream.Close()
End If
Catch ex As Exception
lblResults.Text &= "<li>" & ex.ToString
Finally
objEncryptor.Dispose()
End Try
End Sub

Private Sub cmdDecrypt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDecrypt.Click

Dim arrDESKey As Byte()
Dim arrDESIV As Byte()
Dim objFileStream As FileStream
Dim objDES As DESCryptoServiceProvider
Dim objDecryptor As ICryptoTransform
Dim objCryptoStream As CryptoStream

If Raducu.Utils.FileExists(MapPath("Secret.txt")) Then
Try
arrDESKey =
Raducu.Utils.ConvertToByteArray(ConfigurationSetti ngs.AppSettings("DESKey"))
arrDESIV =
Raducu.Utils.ConvertToByteArray(ConfigurationSetti ngs.AppSettings("DESIV"))
objDES = New DESCryptoServiceProvider()
objDecryptor = objDES.CreateEncryptor(arrDESKey, arrDESIV)
objFileStream = New FileStream(MapPath("Secret.txt"),
FileMode.Open, FileAccess.Read)
objCryptoStream = New CryptoStream(objFileStream,
objDecryptor, CryptoStreamMode.Read)
txtDecrypt.Text = New
StreamReader(objCryptoStream).ReadToEnd
objCryptoStream.Close()
objFileStream.Close()
Catch ex As Exception
lblResults.Text &= "<li>" & ex.ToString
Finally
objDecryptor.Dispose()
End Try
Else
lblResults.Text &= "<li>" & "The file '" &
MapPath("Secret.txt") & " does not exist !"
End If
End Sub
End Class
---------------------------------------------------------------------

Please, could you tell me where is my problem ? The code looks fine to
me...

Thank you, Alex.

Nov 19 '05 #2

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

Similar topics

2
by: Gregory L Priem | last post by:
i have been unable to get any of the classes in the System.Security.Cryptography namespace to work on my w2k machine, so i created a vmware session starting from scratch, to remove any possible...
0
by: Bob Williamson | last post by:
I'm using the RijndaelManaged class to encrypt files. I have the code working but appear to be limited to files less than the maximum size of an integer (about 2GB). The CryptoStream.Read method...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
6
by: Michael Sparks | last post by:
Hi, I suspect this is a bug with AMK's Crypto package from http://www.amk.ca/python/code/crypto , but want to check to see if I'm being dumb before posting a bug report. I'm looking at...
0
by: Cory Baker | last post by:
Hi all! I am trying to encrypt data with C# and decrypt the same data using VC++ 6, both using a password. I believe that I am very close on this one but am currently stuck and am receiving...
13
by: Andy Chau | last post by:
I try to use RSA to implement the following scheme but wasn't sucessful. Sever encrypt a message using a public key, the client decrpyt the message using a private key. I don't want the client...
5
by: William Stacey [MVP] | last post by:
The Decypt2() method below does not work. It completes, but does not do the right thing. The first transform request returns 0 bytes. The first Decypt() method works as we work on a stream...
5
by: ~~~ .NET Ed ~~~ | last post by:
Anybody has any idea why this simple thing is not working? I pass a text file as input to encrypt it, then pass the encrypted version to the same function and get some garbled data not at all...
0
by: Slug | last post by:
Hello all, I've been trying to get a public key solution working but have been having a few problems. For starters there is a lot of contradictory information out there, MSDN is not much help,...
12
by: Fett | last post by:
I need a crypto package that works on windows with python 2.5. Can anyone suggest one for me? I have been searching for a couple days for a good cryptography package to use for public/private...
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
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,...
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...
1
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...
0
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...
0
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...
0
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...
0
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 ...

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.