Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 17th, 2007, 10:52 AM
Registered User
 
Join Date: Jan 2007
Location: delhi, delhi, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mannuvashishta Send a message via Yahoo to mannuvashishta
Default How to generate public and private keys using RSA

Hi
Myself Manu, Currently i am working on cryptography project. I need your help to generate a public and private keys using the RSA algorithm. I have copy my code here can you correct this code and send back to me on my email address mannuvashishta@hotmail.com.
Thank you very much
Manu Vashishta

Visual Basic Dot Net Programming code to generate public key as well as private key.


 Dim GLOIP As IPAddress
    Dim GLOINTPORT As Integer
    Dim bytCommand As Byte() = New Byte() {}
    Dim udpClient As New UdpClient
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a1, b1, c2, d1 As Long
        Dim A, i As Integer
        Dim c, d, t As Byte
        Dim b As Char
        'Dim objCrypto As SymmCrypto = New SymmCrypto
        Dim c1 As String = ""
        'Dim sEncrypted As String
        'Dim sDecrypted As String
        'Dim Key As String
        'Dim sInput As String = TextBox1.Text
        'Key = "1234567"

        ' objCrypto.SymmCrypto(SymmCrypto.SymmProvEnum.DES)
        ' sEncrypted = objCrypto.Encrypting(sInput, Key)
        ' MessageBox.Show("Input Value = " + sInput)
        'MessageBox.Show("Encrypted Value = " + sEncrypted)



        If TextBox1.Text <> "" Then
            For A = 1 To TextBox1.TextLength - 1
                b = TextBox1.Text.Chars(A)
                c1 += Chr(Asc(b) Or (128))
                c = "&Hc1" ' start with 1000 0000
                d = "&Hc" ' value to convert and print into binary
                'TextBox1.Text = ""
                For i = 1 To 8
                    t = d And c '
                    If t = &H0 Then ' check if t has zeros only
                        Debug.Write("0")
                        TextBox1.Text = TextBox1.Text + "0"
                    Else
                        TextBox1.Text = TextBox1.Text + "1"
                        Debug.Write("1")
                    End If
                    c = c >> 1 ' shift C to the right one bit
                Next
                'RSA()
                TextBox2.Text = c1
            Next A
        End If
        'Generate a key pair using RSA algoritm
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        End
    End Sub
    Function RSA() As Double
        Dim a1, b1, c2, d1, e, z, p, phi, q As Long
        Dim A, i, n As Integer
        Dim c, d, t As Byte
        Dim b As Char
        Dim PK As Object
        Dim M As Object
        Dim IsPrime As Boolean

        'Generate a Public key

        a1 = Rnd() * 1000000
        b1 = Rnd() * 1000000
        While a1 > 0
            c2 = Sqrt(a1)
            If IsPrime = True Then
            Else
                IsPrime = False
            End If
            q = c2
            While b1 > 0
                d1 = Sqrt(b1)
                If IsPrime = True Then
                Else
                    IsPrime = False
                End If
                p = 1D
                p = p - 1
                q = q - 1
                phi = (p - 1) * (q - 1)
                n = p * q
                For e = 2 To (phi - 1)
                    If i = False Then
                        z = phi Mod e
                        If z = 0 Then
                        Else
                            PK = e
                            i = True
                            TextBox3.Text = PK
                        End If
                    End If
                Next e
                Exit Function
            End While
        End While
        ' Generate a Private key
        e = False
        For q = 1 To 100000
            If e = False Then
                If ((PK * q) Mod phi) = 1 Then
                    M = q
                    e = True
                    TextBox3.Text = M
                End If
            End If
        Next q
    End Function

    'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    ' Dim a As String
    '
    ' a = InputBox("Enter The Secret Key", "Mannu Vashishta")
    '
    ' Dim count As Long, status As Integer, strCfr As String
    '
    ' Dim strANSIInput As String
    '
    ' Dim i As Integer
    '
    ' Dim Index As Integer
    '
    ' TDciph321.DESReset()

    ' ' convert to hex string
    '
    ' For i = 1 To StrLength Step 2
    '
    ' strCfr = strCfr & Chr("&H" & Mid(S, i, 2))
    '
    ' Next
    '
    ' ' convert to an ansi string
    '
    ' strCfr = StrConv(strCfr, vbFromUnicode)
    '
    ' ' decrypt the string
    '
    ' status = TDciph321.DecryptString(strCfr, LenB(strCfr))
    '
    ' ' convert back to Unicode
    '
    '' strANSIInput = StrConv(strCfr, vbUnicode)
    '
    ' Decrypt = strANSIInput
    '
    ' End Function
    ' End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim man As NetworkAccess

        Dim client As UdpClient
        'Dim abc As IPv6MulticastOption
        Dim GLOINTPORT As Integer
        Dim bytCommand As Byte() = New Byte() {}
        Dim pRet As Integer
        GLOIP = IPAddress.Parse(TextBox2.Text)
        GLOINTPORT = TextBox2.Text
        UdpClient.Connect(GLOIP, GLOINTPORT)
        bytCommand = Encoding.ASCII.GetBytes(TextBox2.Text)
        pRet = UdpClient.Send(bytCommand, bytCommand.Length)
        Console.WriteLine("No messagae send " & pRet)

        ' Returns True if connection is available
        ' Replace www.yoursite.com with a site that
        ' is guaranteed to be online - perhaps your
        ' corporate site, or microsoft.com
        ' Dim objUrl As New System.Uri("http://www.hotmail.com/")
        ' Setup WebRequest
        'Dim objWebReq As System.Net.WebRequest
        'objWebReq = System.Net.WebRequest.Create(objUrl)
        'Dim objResp As System.Net.WebResponse
        'Try
        ' Attempt to get response and return True
        'objResp = objWebReq.GetResponse
        'objResp.Close()
        'objWebReq = Nothing
        'Return True
        'Catch ex As Exception
        ' ' Error, exit and return False
        ' objResp.Close()
        ' objWebReq = Nothing
        ' Return False
        ' End Try

    End Sub
End Class


mannuvashishta
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrapping RSA Keys rayback_2 BOOK: Beginning Cryptography with Java 3 April 28th, 2008 04:29 PM
Access modifiers private and public markhh Java Basics 3 February 21st, 2008 04:56 AM
Encrypted private keys in keystore tomhay BOOK: Beginning Cryptography with Java 2 December 10th, 2006 08:35 AM
prob with certificate's public/private key shiby_chacko1@rediffmail. C# 0 April 5th, 2005 07:18 AM
event handlers declared as private or public ACE2084 ASP.NET 1.0 and 1.1 Basics 3 January 24th, 2005 12:28 PM



All times are GMT -4. The time now is 02:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.