Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Cryptography
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Cryptography

 Post Reply Post Reply
Author
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Topic: Cryptography
    Posted: 10 September 2003 at 10:50am

Hi all, yes I've got yet another 'problem'.

This time it is about encrypting data, not really decripting. I think I need the System.Security.Cryptography namespace, since that's the one they recomment at msdn.microsoft.com.

Well, all I want is to encode an input string using MD5 or DES and select the security strenght, or bits (128-bit or 256-bit). Then I want to respond the output string.

Like: Input > Proces > Response.Write(Output)

Gone..
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 10 September 2003 at 12:28pm

Not like ton's of responses, so lets keep it easy.

I just want an input string to be encrypted like this

Dim InputString As String

InputString = "Testing"

Response.Write(SHA512.Create.Create(InputString).GetType.ToS tring)

So, why doesn't this work?



Edited by Diep-Vriezer
Gone..
Back to Top
otaku View Drop Down
Newbie
Newbie


Joined: 01 June 2003
Location: Canada
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote otaku Quote  Post ReplyReply Direct Link To This Post Posted: 10 September 2003 at 2:56pm

i'm using this for my encrypt password:

Imports System.Web.Security

Dim xxx As String = "Testing"

Dim str As String = FormsAuthentication.HashPasswordForStoringInConfigFile(xxx, "MD5")

Response.Write(str)



Edited by otaku
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 10 September 2003 at 3:19pm
This works fine, but how can I do the same with SHA512 encryption (just to be sure the data is ok )? This is not possible with this function, since I can choose between MD5 and SHA1
Gone..
Back to Top
otaku View Drop Down
Newbie
Newbie


Joined: 01 June 2003
Location: Canada
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote otaku Quote  Post ReplyReply Direct Link To This Post Posted: 10 September 2003 at 3:43pm

I just find a tutorial (5 pages) with example and explanation, folllow the link below see if that's help you

http://www.devx.com/codemag/Article/16747/0/page/1

Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 10 September 2003 at 11:40pm

Let's see...

Thx Alot, this may just the thing I need

Gone..
Back to Top
otaku View Drop Down
Newbie
Newbie


Joined: 01 June 2003
Location: Canada
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote otaku Quote  Post ReplyReply Direct Link To This Post Posted: 11 September 2003 at 6:31am

I found working code (Rijndael Algorithm => Advanced Encryption Standard) which could interest you.

Let's start with the class =>  Crypto.vb

Imports System.IO
Imports System.Text
Imports System.ComponentModel
Imports System.Security.Cryptography

Public Class Crypto

    Public Function EncryptString(ByVal InputString As String, ByVal PassPhrase As String, Optional ByVal IVString As String = vbNullString) As String

        Dim CryptProvider As New RijndaelManaged()
        Dim hashMD5 As New MD5CryptoServiceProvider()
        Dim InputbyteArray() As Byte = Encoding.UTF8.GetBytes(InputString)

        CryptProvider.Key = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(PassPhrase) )
        CryptProvider.IV = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(IVString))
        CryptProvider.Mode = CipherMode.CBC

        Dim ms As MemoryStream = New MemoryStream()
        Dim cs As CryptoStream = New CryptoStream(ms, _
        CryptProvider.CreateEncryptor(), CryptoStreamMode.Write)
        cs.Write(InputbyteArray, 0, InputbyteArray.Length)
        cs.FlushFinalBlock()

        Dim ret As StringBuilder = New StringBuilder()
        Dim b() As Byte = ms.ToArray
        Dim I As Integer
        Dim Out As String
        For I = 0 To UBound(b)
             'Format as hex
             ret.AppendFormat("{0:X2}", b(I))
        Next
        Return ret.ToString()

    End Function

    Public Function DecryptString(ByVal InputString As String, ByVal PassPhrase As String, ByVal IVString As String) As String

        Dim DES As New RijndaelManaged()

        Dim hashMD5 As New MD5CryptoServiceProvider()

        DES.Key = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(PassPhrase) )
        DES.IV = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(IVString))
        DES.Mode = CipherMode.CBC
        'Put the input string into the byte array
        Dim inputByteArray(InputString.Length / 2 - 1) As Byte
        Dim X As Integer
        For X = 0 To InputString.Length / 2 - 1
             Dim IJ As Integer = (Convert.ToInt32(InputString.Substring(X * 2, 2), 16))
             Dim BT As New ByteConverter()
             inputByteArray(X) = New Byte()
             inputByteArray(X) = BT.ConvertTo(IJ, GetType(Byte))
        Next

        'Create the crypto objects
        Dim MS As MemoryStream = New MemoryStream()
        Dim CS As CryptoStream = New CryptoStream(MS, DES.CreateDecryptor(), CryptoStreamMode.Write)

        'Flush the data through the crypto stream into the memory stream
        CS.Write(inputByteArray, 0, inputByteArray.Length)
        CS.FlushFinalBlock()

        'Get the decrypted data back from the memory stream
        Dim ret As StringBuilder = New StringBuilder()
        Dim B() As Byte = MS.ToArray
        Dim I As Integer
        For I = 0 To UBound(B)
             ret.Append(Chr(B(I)))
        Next
        Return ret.ToString()

    End Function

End Class


Then create an other page whatever.aspx, create an instance of our Crypto class
and use the 2 functions of that Crypto class for encrypt and decrypt your string:

Sub Page_Load(.................

Dim Crypt As New Crypto()
Dim TestString, PassPhrase, IVPhrase, CryptString, DecryptString As String
TestString = "Testing"
PassPhrase = "This is a passphrase"
IVPhrase = "This is an IV phrase"

Response.Write("Original String: " & TestString & "<br />")

CryptString = Crypt.EncryptString(TestString, PassPhrase, IVPhrase)
Response.Write("EnCrypt String: " & CryptString & "<br />")

DecryptString = Crypt.DecryptString(CryptString, PassPhrase, IVPhrase)
Response.Write("DeCrypt String: " & DecryptString & "<br />")

End Sub



Edited by otaku
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 11 September 2003 at 7:58am

 Fantastic

Dude, you rock, this is exactly what I wanted! Thx!

Gone..
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.