Encryption and Decryption of xml file

Asked By swati
17-Mar-10 03:11 AM
Earn up to 0 extra points for answering this tough question.
Hi.....
Is anyone having the code/algorithm for encrypting and decrypting xml file in ASP VB?
I am getting the algorithms for encryption but not for decryption....
Please suggest..

  re: Encryption and Decryption of xml file

Sandra Jain replied to swati
17-Mar-10 03:21 AM
Here you go. This will encrypt the DES3 key in a 128 bit MD5Hash and then use that hash to encrypt at the 3x64 (192bit) DES3.

Imports System.Web.Security
Imports System.Security.Cryptography
Imports System.Text
Imports Microsoft.Win32

Public Class Crypt

Dim myKey As String
Dim cryptDES3 As New TripleDESCryptoServiceProvider()
Dim cryptMD5Hash As New MD5CryptoServiceProvider()

Public Sub New()

myKey = "somekeyhere"

End Sub

Private Function Decrypt(ByVal myString As String) As String
cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(myKey))
cryptDES3.Mode = CipherMode.ECB
Dim desdencrypt As ICryptoTransform = cryptDES3.CreateDecryptor()
Dim buff() As Byte = Convert.FromBase64String(myString)
Decrypt = ASCIIEncoding.ASCII.GetString(desdencrypt.TransformFinalBlock(buff, 0, buff.Length))
End Function

Private Function Encrypt(ByVal myString As String) As String
cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(myKey))
cryptDES3.Mode = CipherMode.ECB
Dim desdencrypt As ICryptoTransform = cryptDES3.CreateEncryptor()
Dim MyASCIIEncoding = New ASCIIEncoding()
Dim buff() As Byte = ASCIIEncoding.ASCII.GetBytes(testo)
Encrypt = Convert.ToBase64String(desdencrypt.TransformFinalBlock(buff, 0, buff.Length))
End Function

End Class

  re: Encryption and Decryption of xml file

Sandra Jain replied to swati
17-Mar-10 03:22 AM
Also refer:

http://www.obviex.com/samples/dpapi.aspx

http://www.developerfusion.com/code/157/encryptdecrypt/

http://www.dotnetcurry.com/ShowArticle.aspx?ID=185&AspxAutoDetectCookieSupport=1

  re: Encryption and Decryption of xml file

Super Man replied to swati
17-Mar-10 03:27 AM

this article provides you the best example for encryption and dectyption


http://www.codeproject.com/KB/security/SecretEncryptionDemo.aspx

  re: re: Encryption and Decryption of xml file
swati replied to Sandra Jain
17-Mar-10 03:58 AM
Will this code work for an XML file..?
and I need this code for ASP pages not for ASP.net...
Please suggest

Thanks for ur support
  re: Encryption and Decryption of xml file
Santhosh N replied to swati
17-Mar-10 04:29 AM
You could actually encrypt and decrypt strings in vbscript and you could actually have xml as string and do encryption and decryption on the string (which is nothing but the xml)
check here for more info..
http://www.example-code.com/vbscript/rsa_encryptStrings.asp
  re: re: Encryption and Decryption of xml file
swati replied to Sandra Jain
24-Mar-10 06:17 AM
Hi sandra..
I tried to run the code given by you.but what is "testo" there..?
it's throwing an error.
thanks,
Create New Account