Is this the sort of thing you after?

 

Anthony

 

    'The function used to encrypt the text

    Private Shared Function Encrypt(ByVal strText As String, ByVal
strEncrKey As String) As String

        Dim byKey() As Byte = {}

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

 

            byKey = System.Text.Encoding.UTF8.GetBytes(Left(strEncrKey, 8))

 

            Dim des As New DESCryptoServiceProvider

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

            Dim ms As New MemoryStream

            Dim cs As New CryptoStream(ms, des.CreateEncryptor(byKey, IV),
CryptoStreamMode.Write)

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

            cs.FlushFinalBlock()

            Return Convert.ToBase64String(ms.ToArray())

 

 

    End Function

 

    Private Shared Function Decrypt(ByVal strText As String, ByVal sDecrKey
As String) As String

        Dim byKey() As Byte = {}

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

        Dim inputByteArray(strText.Length) As Byte

 

            byKey = System.Text.Encoding.UTF8.GetBytes(Left(sDecrKey, 8))

            Dim des As New DESCryptoServiceProvider

            inputByteArray = Convert.FromBase64String(strText)

            Dim ms As New MemoryStream

            Dim cs As New CryptoStream(ms, des.CreateDecryptor(byKey, 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())

 

 

    End Function

 

 

From: [email protected] [mailto:[email protected]]
On Behalf Of Stephen Price
Sent: Friday, 22 March 2013 1:06 PM
To: ozDotNet
Subject: Encryption

 

Hey all,

 

http://msdn.microsoft.com/en-us/library/ms229741.aspx

 

"...which allows you to encrypt data using information from the current user
account or computer. "

 

I'm using ProtectedData to encrypt and decrypt passwords so they can be
stored in database encrypted, but they want to be able to see what the
password is for administrators. It all works great except when a user logs
in (using a custom principal, not the user who did the encryption.. ie the
Admin) and it doesn't work as the user is different, or the machine is
different. 

 

I'm looking for a way to encrypt and decrypt at an app level rather than
user/machine level. Don't mind if keys are involved. Anyone done this and is
there a framework class somewhere for that?

 

cheers,

Stephen

Reply via email to