Bitcoin Forum
June 19, 2024, 05:06:33 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: check sum a base58 private key  (Read 129 times)
dude1234321 (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 2


View Profile
December 28, 2021, 12:32:17 PM
 #1

hi,

i want some code, preferably .net (c# or vb.net) to check sum base 58 (51 character) private keys to see if they are valid or not.

can anyone point me in the right direction?

thank you

PawGo
Legendary
*
Offline Offline

Activity: 952
Merit: 1367


View Profile
December 28, 2021, 12:39:59 PM
 #2

Take a look here:
https://learnmeabitcoin.com/technical/wif

Checksum is in fact double sha256. You will have to decode your private key, remove last 4 bytes (8 decoded characters), calculate double hash and compare first 4 bytes (8 characters) of result with checksum received after decoding WIF.

Maybe this is what you look for:
https://gist.github.com/CodesInChaos/3175971#file-base58encoding-cs
dude1234321 (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 2


View Profile
December 28, 2021, 12:45:16 PM
 #3

thank you for the information.

is there no library out there ? all i want to do is run some code that does

print IsValidKey("testkey")

i.e. prints true or false

there must be some library out there already that does that?
NeuroticFish
Legendary
*
Offline Offline

Activity: 3710
Merit: 6426


Looking for campaign manager? Contact icopress!


View Profile
December 28, 2021, 12:46:47 PM
 #4

Although it tells it's not optimized, you may find useful parts for your needs here: https://gist.github.com/CodesInChaos/3175971
Another one I've found is https://github.com/adamcaudill/Base58Check and you can get it as NuGet package.
Both are not my code, I've just found them on the internet.



█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
PawGo
Legendary
*
Offline Offline

Activity: 952
Merit: 1367


View Profile
December 28, 2021, 12:48:07 PM
 #5

Please check carefully the code I sent you. There is method DecodeWithChecksum, which returns correctly decoded private key or throws exception if checksum is invalid, just like you want.
dude1234321 (OP)
Newbie
*
Offline Offline

Activity: 23
Merit: 2


View Profile
December 28, 2021, 12:52:00 PM
 #6

Please check carefully the code I sent you. There is method DecodeWithChecksum, which returns correctly decoded private key or throws exception if checksum is invalid, just like you want.

oh yes just saw that, will try it out, thank you Smiley
BlackHatCoiner
Legendary
*
Offline Offline

Activity: 1554
Merit: 7566


Protocols over bureaucrats


View Profile
December 28, 2021, 12:53:30 PM
Merited by ABCbits (1)
 #7

Since you want it to be .NET, check Autarkysoft.Bitcoin/Encoders/Base58.cs of Coding Enthusiast. The boolean you're searching is IsValid(string encoded). Check his stuff, he has done some pretty good work.

.
.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!