-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: BusyWizy
Message 3 in Discussion




Refer to the following code snippets


   
Private
key()
As
Byte
= {}

   
Private
IV()
As
Byte
= {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD,
&HEF}


Public
Function
Encrypt(ByVal
stringToEncrypt
As
String,
_

       
ByVal
SEncryptionKey
As
String
= "")
As
String


       
Try

           
key = System.Text.Encoding.UTF8.GetBytes(Left(SEncryptionKey, 8))

           
Dim
des
As
New
DESCryptoServiceProvider

           
Dim
inputByteArray()
As
Byte
= Encoding.UTF8.GetBytes( _

               
stringToEncrypt)

           
Dim
ms
As
New
MemoryStream

           
Dim
cs
As
New
CryptoStream(ms, des.CreateEncryptor(key, IV), _

               
CryptoStreamMode.Write)

           
cs.Write(inputByteArray, 0, inputByteArray.Length)

           
cs.FlushFinalBlock()

           
Return
Convert.ToBase64String(ms.ToArray())

       
Catch
e
As
Exception

           
Return
e.Message

       
End
Try

   
End
Function


Public
Function
Decrypt(ByVal
stringToDecrypt
As
String,
_

       
ByVal
sEncryptionKey
As
String
= "")
As
String


       
Dim
inputByteArray(stringToDecrypt.Length)
As
Byte


       
Try

           
key = System.Text.Encoding.UTF8.GetBytes(Left(sEncryptionKey, 8))

           
Dim
des
As
New
DESCryptoServiceProvider

           
inputByteArray = Convert.FromBase64String(stringToDecrypt)

           
Dim
ms
As
New
MemoryStream

           
Dim
cs
As
New
CryptoStream(ms, des.CreateDecryptor(key, IV), _

               
CryptoStreamMode.Write)

           
cs.Write(inputByteArray, 0, inputByteArray.Length)

           
cs.FlushFinalBlock()

           
Dim
encoding
As
System.Text.Encoding = System.Text.Encoding.UTF8

           
Return
encoding.GetString(ms.ToArray())

       
Catch
e
As
Exception

           
Return
e.Message

       
End
Try

   
End
Function




regards,

nauzad kapadia [mvp]


From: cyberbhaskar

Message 1 in Discussion


Want to encrypt a string using System.Security.Cryptography


Can anyone brief about keys etc., in  System.Security.Cryptography
and provide sample code.


Please Advise!!!


Thank You

Bhaskar Prasad Thamma






-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to