Author

Topic: private key to public key generation bitcoin vb.net gives unknown error (Read 125 times)

legendary
Activity: 3472
Merit: 10611
additionally the elliptic curve that you are using is called secp256r1 (not ...k1) which is a different curve than what bitcoin uses so your key pairs should also be different and invalid in bitcoin.
i am assuming you are just learning things but be very careful if you want to use whatever you are making with real funds. it is also best if you find a bitcoin library and use that instead of .net framework.
legendary
Activity: 4522
Merit: 3426
I'm trying to use secp256k1 eliptic curve to get the public key from private key but it gives me an unknown error error

Quote
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
    Dim private_key = "68040878110175628235481263019639686"
    'public key should be Nr6MbFUfMovKCX4vd5YpQnRYsN4rq6pNPEEBKmicAEwwuYLpJrt5LsRvfvR2G8pJ5rMchEMWDYJ7rdY GY7PjxHEa
    Dim public_key As String


    Using eliptic As New ECDsaCng()
        eliptic.HashAlgorithm = CngAlgorithm.ECDsaP256

        Dim data() As Byte = Encoding.UTF8.GetBytes(private_key)
        Dim key As Byte() = eliptic.SignData(data)
        public_key = key.ToString
    End Using

    TextBox15.Text = public_key
End Sub

I'm not an expert, but after looking at the docs (https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.ecdsacng?view=netframework-4.8), I think I see several problems:

1. New ECDsaCng() initializes an instance with a random key pair.
2. ECDsaCng.SignData() does not return a public key. It signs a message. In this case it is signing the message "68040878110175628235481263019639686" ad returning the signatre.
3. Encoding.UTF8.GetBytes() does not covert a string to a number.
4. Byte.ToString() does not encode data using base-64

To extract the public key from ECDsaCng (once it is initialized correctly), I believe you can use ECDsaCng.Key.Export(). However, I can't figure out how to import the private key in the first place. Perhaps, ECDsaCng is not appropriate for what you are trying to do. Generating the public key is straightforward, but I don't know how to do it in .NET.
newbie
Activity: 7
Merit: 10
I'm trying to use secp256k1 eliptic curve to get the public key from private key but it gives me an unknown error error

Quote
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
    Dim private_key = "68040878110175628235481263019639686"
    'public key should be Nr6MbFUfMovKCX4vd5YpQnRYsN4rq6pNPEEBKmicAEwwuYLpJrt5LsRvfvR2G8pJ5rMchEMWDYJ7rdY GY7PjxHEa
    Dim public_key As String


    Using eliptic As New ECDsaCng()
        eliptic.HashAlgorithm = CngAlgorithm.ECDsaP256

        Dim data() As Byte = Encoding.UTF8.GetBytes(private_key)
        Dim key As Byte() = eliptic.SignData(data)
        public_key = key.ToString
    End Using

    TextBox15.Text = public_key
End Sub
Jump to: