473,231 Members | 1,619 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,231 software developers and data experts.

convert string to CipherMessage

Is there a way to convert a string to a CipherMessage? I am calling a
function that decrypts a CipherMessage and returns the value. The only
problem is when I want to use an encrypted value stored in a querystring, I
can't figure out how to convert it back to a CipherMessage.

Jul 21 '05 #1
2 2701
Hi,

What is the function you are using? Which encryption class is it using?

MSDN details encryption and decryption of strings here:
http://msdn.microsoft.com/library/en...yptingdata.asp

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.msmvps.com/rakeshrajan/

"Nathan" wrote:
Is there a way to convert a string to a CipherMessage? I am calling a
function that decrypts a CipherMessage and returns the value. The only
problem is when I want to use an encrypted value stored in a querystring, I
can't figure out how to convert it back to a CipherMessage.

Jul 21 '05 #2
Private rsa As RSACryptoServiceProvider
Private rc2 As RC2CryptoServiceProvider

Public Function EncryptMessage(ByVal [text] As String) As CipherMessage
' Convert string to a byte array
Dim message As New CipherMessage
Dim plainBytes As Byte() =
Encoding.Unicode.GetBytes([text].ToCharArray())

' A new key and iv are generated for every message
Dim bEncryptedValue As Object
Dim bIV As Object

Dim oPassword As Password = New Password
Dim m_bDESKEY As Byte() = ASCIIEncoding.ASCII.GetBytes("ys6s5s4s")
Dim m_bDESIV As Byte() = ASCIIEncoding.ASCII.GetBytes("fu27shw6")
Dim sPass As String

rc2.Key = m_bDESKEY
rc2.IV = m_bDESIV
'rc2.GenerateKey()
'rc2.GenerateIV()

' The rc2 initialization doesnt need to be encrypted, but will
' be used in conjunction with the key to decrypt the message.
message.rc2IV = rc2.IV
Try
' Encrypt the RC2 key using RSA encryption
message.rc2Key = rsa.Encrypt(rc2.Key, False)
Catch e As CryptographicException
' The High Encryption Pack is required to run this sample
' because we are using a 128-bit key. See the readme for
' additional information.
Console.WriteLine(("Encryption Failed. Ensure that the" + " High
Encryption Pack is installed."))
Console.WriteLine(("Error Message: " + e.Message))
Environment.Exit(0)
End Try
' Encrypt the Text Message using RC2 (Symmetric algorithm)
Dim sse As ICryptoTransform = rc2.CreateEncryptor()
Dim ms As New MemoryStream
Dim cs As New CryptoStream(ms, sse, CryptoStreamMode.Write)
Try
cs.Write(plainBytes, 0, plainBytes.Length)
cs.FlushFinalBlock()
message.cipherBytes = ms.ToArray()
Catch e As Exception
Console.WriteLine(e.Message)
Finally
ms.Close()
cs.Close()
End Try
Return message
End Function 'EncryptMessage

Public Function DecryptMessage(ByVal message As CipherMessage)
Dim sMessage As String
' Get the RC2 Key and Initialization Vector
rc2.IV = message.rc2IV
Try
' Try decrypting the rc2 key
rc2.Key = rsa.Decrypt(message.rc2Key, False)
Catch e As CryptographicException
sMessage = "Decryption Failed: " + e.Message
Return sMessage
End Try

Dim ssd As ICryptoTransform = rc2.CreateDecryptor()
' Put the encrypted message in a memorystream
Dim ms As New MemoryStream(message.cipherBytes)
' the CryptoStream will read cipher text from the MemoryStream
Dim cs As New CryptoStream(ms, ssd, CryptoStreamMode.Read)
Dim initialText() As Byte = New [Byte](message.cipherBytes.Length) {}

Try
' Decrypt the message and store in byte array
cs.Read(initialText, 0, initialText.Length)
Catch e As Exception
Console.WriteLine(e.Message)
Finally
ms.Close()
cs.Close()
End Try

' Display the message received
sMessage = name + " received the following message:"
sMessage += " " & Encoding.Unicode.GetString(initialText)
Return sMessage
End Function 'DecryptMessage

"Rakesh Rajan" wrote:
Hi,

What is the function you are using? Which encryption class is it using?

MSDN details encryption and decryption of strings here:
http://msdn.microsoft.com/library/en...yptingdata.asp

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.msmvps.com/rakeshrajan/

"Nathan" wrote:
Is there a way to convert a string to a CipherMessage? I am calling a
function that decrypts a CipherMessage and returns the value. The only
problem is when I want to use an encrypted value stored in a querystring, I
can't figure out how to convert it back to a CipherMessage.

Jul 21 '05 #3

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

Similar topics

4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
2
by: Nathan | last post by:
Is there a way to convert a string to a CipherMessage? I am calling a function that decrypts a CipherMessage and returns the value. The only problem is when I want to use an encrypted value stored...
4
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
9
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.