DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: .NET encryption

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    39

    Question .NET encryption

    I found this article, but for me is hard to learn

    http://www.devx.com/security/Article/7019

    can helpme a little bit with this:
    I want:

    1.- the user insert the password
    2.- this is encrypted, later is compared with the password into access database.


    please help.
    "Quid quid agis prudenter agas et respice finem"
    (Hagas lo que hagas, act˙a inteligentemente y considerando el fin)
    MyNeoReport - The "FREE" Report Generator for .NET
    http://myneoreport.sourceforge.net/
    http://www.frappr.com/vbcity

  2. #2
    Join Date
    Apr 2005
    Posts
    39

    ready!!

    for any user in the board.

    Imports System
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports Microsoft.visualBasic
    Imports System.Security.Cryptography
    imports System.Security.Cryptography.RSACryptoServiceProvider
    Imports System.Text
    Imports System.Xml
    Imports System.IO

    .....


    Dim keypub1 As String
    Dim keypub2 As String

    Dim rsa As New RSACryptoServiceProvider
    Dim plaintext() As Byte
    rsa.FromXmlString(keypub1)
    plaintext = rsa.Decrypt(HexStringToByteArray(Valor), False)
    Valor1X = ByteArrayToString(plaintext) ' value from database



    Private Sub Form9Load(sender As System.Object, e As System.EventArgs)
    keypub1 = "<RSAKeyValue><Modulus>mqE877PJY7TXrrX7FlV32XSF7efx3gITMBRj7GNKuEzAnkPHIuMm2Bide/SydMJ3Cmbs7E5cIq7aU4p731WaHMsPuXwYrRuBA/3CC3KxlXcqvkqxgyaZch6CidqxCvBc36dRGgxazDN72tCYmaOfvHFjqgDj0WWLympwh3tnehs=</Modulus><Exponent>AQAB</Exponent><P>yGTf6H1OhGrIOZ/db9b3ADpDvY28gU74Z31ZogHbTF5ygf1w0E/6IImLhJi5AX7Q4fWW3W5XRTNm1Z97sVmIhw==</P><Q>xYl46WAID8C5GVUUH7iyJgmeDOBIKeqY5VlXf3HJ4wzZaVzf366SLjDvctNEofekWeIX5erDmNFLlBmh7fkqz Q==</Q><DP>iLbBR1SNx6suFJorMUzf0GjvpBdZfoKI19nd17gai9x3lJV6bLPTenU8GOc0eH+zNCUfmsvXgB+UTbNzaMgj aw==</DP><DQ>FHKmkYHfU8IfZv/nlWEJD+bu9WZCEhS2vwcAh7C/tUEfQEjc48quVxm5r6ku8ZUw7hz5XFNw6+C+chY1LO0eAQ==</DQ><InverseQ>VEsm4jabkFg9R000XxL/7f5qv075GEzuE9yjH5hxGn+J+K0Gvt2HC5G7euaMD1RQeHdGYhBV5hHqbyk67GpkFw==</InverseQ><D>eSd+TD2svG+UUnKJog0jU4FF8oq6an1rtU80n6GIiPCyNw7Z907NP6HBur6WGH/Jr5/HYLtg21fu/mfR+MHkdhUmksuupHRzHmdfPjpFeRhGWlwxBef6znbZ03wITDKp1Vv/1/OC4BkHHmdV2YES1pVw8VBd3/g+dCMTkmD68mk=</D></RSAKeyValue>"
    keypub2 = "<RSAKeyValue><Modulus>mqE877PJY7TXrrX7FlV32XSF7efx3gITMBRj7GNKuEzAnkPHIuMm2Bide/SydMJ3Cmbs7E5cIq7aU4p731WaHMsPuXwYrRuBA/3CC3KxlXcqvkqxgyaZch6CidqxCvBc36dRGgxazDN72tCYmaOfvHFjqgDj0WWLympwh3tnehs=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"
    End Sub

    Public Shared Function ByteArrayToHexString(ByRef bInput As Byte()) As String
    Dim i As Integer, strOutput As String, c As Integer, c1 As Integer, c2 As Integer

    For i = 0 To (bInput.Length - 1)
    c = bInput(i)
    c2 = c Mod 16
    c1 = (c - c2) / 16
    If (c1 >= 0 And c1 <= 9) Then
    c1 = c1 + Asc("0")
    ElseIf (c1 >= &HA And c1 <= &H10) Then
    c1 = c1 + Asc("A") - &HA
    End If
    If (c2 >= 0 And c2 <= 9) Then
    c2 = c2 + Asc("0")
    ElseIf (c2 >= &HA And c2 <= &H10) Then
    c2 = c2 + Asc("A") - &HA
    End If
    strOutput &= Chr(c1) & Chr(c2)
    Next

    Return strOutput
    End Function
    Public Shared Function HexStringToByteArray(ByRef strInput As String) As Byte()
    Dim length As Integer, bOutput As Byte(), c(1) As Integer

    length = strInput.Length / 2
    ReDim bOutput(length - 1)
    For i As Integer = 0 To (length - 1)
    For j As Integer = 0 To 1
    c(j) = Asc(strInput.Chars(i * 2 + j))
    If ((c(j) >= Asc("0")) And (c(j) <= Asc("9"))) Then
    c(j) = c(j) - Asc("0")
    ElseIf ((c(j) >= Asc("A")) And (c(j) <= Asc("F"))) Then
    c(j) = c(j) - Asc("A") + &HA
    ElseIf ((c(j) >= Asc("a")) And (c(j) <= Asc("f"))) Then
    c(j) = c(j) - Asc("a") + &HA
    End If
    Next j
    bOutput(i) = (c(0) * &H10 + c(1))
    Next i

    Return bOutput
    End Function

    Public Shared Function ByteArrayToString(ByRef bInput As Byte()) As String
    Dim i As Long, out As String
    For i = LBound(bInput) To UBound(bInput)
    out = out & Chr(bInput(i))
    Next
    ByteArrayToString = out
    End Function

    Public Shared Function StringToByteArray(ByRef bInput As String) As Byte()
    Dim i As Long, out() As Byte
    ReDim out(Len(bInput) - 1)
    For i = 1 To Len(bInput)
    out(i - 1) = Asc(Mid(bInput, i, 1))
    Next
    StringToByteArray = out
    End Function
    "Quid quid agis prudenter agas et respice finem"
    (Hagas lo que hagas, act˙a inteligentemente y considerando el fin)
    MyNeoReport - The "FREE" Report Generator for .NET
    http://myneoreport.sourceforge.net/
    http://www.frappr.com/vbcity

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center