Barb4253
asked on
Encrypt / Decrypt Date to store in registry
Hi, I need some fairly simple code to encrypt a given date, store it in the registry, then later retrieve it and decrypt it. I don't need 128 bit encryption or anything, just so it's not recognizable (or easily decrypted).
Thanks
Thanks
https://www.experts-exchange.com/questions/21210307/String-Encryption-With-Visual-Basic-NET-and-SQL-Server-2000.html has code for a full decryptor/encryptor posted to it...
In this case you could either convert the date into string reverse it and store it.
In case you want to further encrypt it you could scramble it up in different peices or alternatively get the ascii code for each individual character then add or substract a certain digit to it and reconvert it into a character, join it up and store it into the registry.
Since you will be writing to the registry I presume that you would know quite a bit of coding and therefore I am not putting the code here. In case you do require it do let me know
In case you want to further encrypt it you could scramble it up in different peices or alternatively get the ascii code for each individual character then add or substract a certain digit to it and reconvert it into a character, join it up and store it into the registry.
Since you will be writing to the registry I presume that you would know quite a bit of coding and therefore I am not putting the code here. In case you do require it do let me know
ASKER
Thank you both. Chaosian, I also saw that code... but simple is key! JasonRodrigues, That would be simple, however, I thought there was a simple encryption/decryption function within vb.net, no???
Thanks again,
Barb
Thanks again,
Barb
There's a simple "encryption" function for passwords -- HashPasswordForStoringInCo nfigFile. This might be what you're thinking of. The problem is that hashing is a one-way process. You can't get the original date back -- you'd have to hash the new date and compare the hashes.
You could do something simple like casting the date to a single -- this would make it a decimal number. Then, if you wanted to take it a step further, you could perform some operation on it -- square the decimal portion, multiply the whole thing by a constant, etc, etc.
You could do something simple like casting the date to a single -- this would make it a decimal number. Then, if you wanted to take it a step further, you could perform some operation on it -- square the decimal portion, multiply the whole thing by a constant, etc, etc.
Still intereseted in helping resolve this question.
Thanks.
Thanks.
ASKER
I ended up using a TripleDES class:
Imports System.IO
Imports System.Text
Imports System.Security.Cryptograp hy
Friend Class cTripleDES
Private m_des As New TripleDESCryptoServiceProv ider
' define the string handler
Private m_utf8 As New UTF8Encoding
' define the local property arrays
Private m_key() As Byte
Private m_iv() As Byte
Public Sub New(ByVal key() As Byte, ByVal iv() As Byte)
Me.m_key = key
Me.m_iv = iv
End Sub
Public Function Encrypt(ByVal input() As Byte) As Byte()
Return Transform(input, m_des.CreateEncryptor(m_ke y, m_iv))
End Function
Public Function Decrypt(ByVal input() As Byte) As Byte()
Return Transform(input, m_des.CreateDecryptor(m_ke y, m_iv))
End Function
Public Function Encrypt(ByVal text As String) As String
Dim input() As Byte = m_utf8.GetBytes(text)
Dim output() As Byte = Transform(input, m_des.CreateEncryptor(m_ke y, m_iv))
Console.WriteLine(m_des.Ke ySize.ToSt ring)
Return Convert.ToBase64String(out put)
End Function
Public Function Decrypt(ByVal text As String) As String
Dim input() As Byte = Convert.FromBase64String(t ext)
Dim output() As Byte = Transform(input, m_des.CreateDecryptor(m_ke y, m_iv))
Return m_utf8.GetString(output)
End Function
Private Function Transform(ByVal input() As Byte, _
ByVal CryptoTransform As ICryptoTransform) As Byte()
' create the necessary streams
Dim memStream As MemoryStream = New MemoryStream
Dim cryptStream As CryptoStream = New _
CryptoStream(memStream, CryptoTransform, _
CryptoStreamMode.Write)
' transform the bytes as requested
cryptStream.Write(input, 0, input.Length)
cryptStream.FlushFinalBloc k()
' Read the memory stream and convert it back into byte array
memStream.Position = 0
Dim result(CType(memStream.Len gth - 1, System.Int32)) As Byte
memStream.Read(result, 0, CType(result.Length, System.Int32))
' close and release the streams
memStream.Close()
cryptStream.Close()
' hand back the encrypted buffer
Return result
End Function
End Class
Imports System.IO
Imports System.Text
Imports System.Security.Cryptograp
Friend Class cTripleDES
Private m_des As New TripleDESCryptoServiceProv
' define the string handler
Private m_utf8 As New UTF8Encoding
' define the local property arrays
Private m_key() As Byte
Private m_iv() As Byte
Public Sub New(ByVal key() As Byte, ByVal iv() As Byte)
Me.m_key = key
Me.m_iv = iv
End Sub
Public Function Encrypt(ByVal input() As Byte) As Byte()
Return Transform(input, m_des.CreateEncryptor(m_ke
End Function
Public Function Decrypt(ByVal input() As Byte) As Byte()
Return Transform(input, m_des.CreateDecryptor(m_ke
End Function
Public Function Encrypt(ByVal text As String) As String
Dim input() As Byte = m_utf8.GetBytes(text)
Dim output() As Byte = Transform(input, m_des.CreateEncryptor(m_ke
Console.WriteLine(m_des.Ke
Return Convert.ToBase64String(out
End Function
Public Function Decrypt(ByVal text As String) As String
Dim input() As Byte = Convert.FromBase64String(t
Dim output() As Byte = Transform(input, m_des.CreateDecryptor(m_ke
Return m_utf8.GetString(output)
End Function
Private Function Transform(ByVal input() As Byte, _
ByVal CryptoTransform As ICryptoTransform) As Byte()
' create the necessary streams
Dim memStream As MemoryStream = New MemoryStream
Dim cryptStream As CryptoStream = New _
CryptoStream(memStream, CryptoTransform, _
CryptoStreamMode.Write)
' transform the bytes as requested
cryptStream.Write(input, 0, input.Length)
cryptStream.FlushFinalBloc
' Read the memory stream and convert it back into byte array
memStream.Position = 0
Dim result(CType(memStream.Len
memStream.Read(result, 0, CType(result.Length, System.Int32))
' close and release the streams
memStream.Close()
cryptStream.Close()
' hand back the encrypted buffer
Return result
End Function
End Class
Glad to see you got it working...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.