Bitcoin Forum
May 09, 2024, 08:26:12 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: private key to public key generation bitcoin vb.net gives unknown error  (Read 142 times)
PrettyGirl741963 (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 10


View Profile
February 25, 2020, 10:08:26 AM
 #1

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
1715243172
Hero Member
*
Offline Offline

Posts: 1715243172

View Profile Personal Message (Offline)

Ignore
1715243172
Reply with quote  #2

1715243172
Report to moderator
1715243172
Hero Member
*
Offline Offline

Posts: 1715243172

View Profile Personal Message (Offline)

Ignore
1715243172
Reply with quote  #2

1715243172
Report to moderator
1715243172
Hero Member
*
Offline Offline

Posts: 1715243172

View Profile Personal Message (Offline)

Ignore
1715243172
Reply with quote  #2

1715243172
Report to moderator
No Gods or Kings. Only Bitcoin
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715243172
Hero Member
*
Offline Offline

Posts: 1715243172

View Profile Personal Message (Offline)

Ignore
1715243172
Reply with quote  #2

1715243172
Report to moderator
odolvlobo
Legendary
*
Offline Offline

Activity: 4298
Merit: 3214



View Profile
February 25, 2020, 08:39:11 PM
Last edit: February 25, 2020, 10:18:03 PM by odolvlobo
Merited by pooya87 (1), ABCbits (1)
 #2

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.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10555



View Profile
February 26, 2020, 03:46:05 AM
Merited by fillippone (2), ABCbits (1)
 #3

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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!