dcsimg
Results 1 to 11 of 11

Thread: VB6 Blockchain Public Key Crypto & Digital Signatures & _ $25 BTC Bounty When Solved

  1. #1

    Thread Starter
    Member backflip's Avatar
    Join Date
    Oct 2013
    Posts
    42

    VB6 Blockchain Public Key Crypto & Digital Signatures & _ $25 BTC Bounty When Solved

    Hey gang,

    Welcome to Episode 3 of "Backflip codes the world's first and last blockchain in VB6."

    With only a surface level understanding of many areas of crypto, there's a learning curve (heh) for me at this step. I'm not sure how to associate public and private keys together with a "mathematical relationship" and tie that into Alice authenticating that Bob has access to the private key associated with his public key.

    Good News: I believe this is one of the final areas for me to nail down before I can program and deploy the VB6 blockchain. I think it'll run on Vista to WS2019 or so, and might actually end up being pretty fast. I'm a junkie for speed optimization.

    Bad news: This appeared to be about the most relevant, easy to use solution - it just didn't work on my computer despite a couple of installs.

    Any ideas?

    What I'm trying to do:



    Best,
    Backflip

    Update: I'm going to see how far I manage to get with this and will report back tomorrow.

    I'm not sure if there are any solid examples of Capicom doing exactly this. i.e. Generating Keypairs, Signing Messages and then Authenticating Signed Messages, but if I am able to make one I will drop it in this thread. If not, I may have questions and maybe more $20 BTC bounties

    Last edited by backflip; Today at 08:57 AM.

  2. #2
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,323

    Re: Generating Keypairs, Signing and Authenticating Signed Digital Signatures in VB6

    The Chilkat library you linked to is a commercial library. Their pricing & redistribution terms are very reasonable, but there is still a cost. I'm still not 100% sure if you want to write everything yourself in VB6 or if you are willing to use paid/other third-party libraries in your project? If you are open to using paid/third-party libraries, I have a license for the Chilkat bundle so I can give it a try to see if I can get things working.

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,420

    Re: Generating Keypairs, Signing and Authenticating Signed Digital Signatures in VB6

    I don't know what those keys and signatures need to be so I'm not sure whether this helps. I haven't had to revisit it seriously in a long time so the details are murky right now too: RSA Data Signing via CNG.

    By working with the APIs instead of wrappers like CAPICOM you do more work but you also get finer control if required.

  4. #4
    Fanatic Member
    Join Date
    Dec 2012
    Posts
    760

    Re: Generating Keypairs, Signing and Authenticating Signed Digital Signatures in VB6

    When looking at third party solutions, keep in mind that the only thing considered secure these days is TLS 1.2 or better.

    J.A. Coutts

  5. #5

    Thread Starter
    Member backflip's Avatar
    Join Date
    Oct 2013
    Posts
    42

    Re: Generating Keypairs, Signing and Authenticating Signed Digital Signatures in VB6

    Quote Originally Posted by jpbro View Post
    The Chilkat library you linked to is a commercial library. Their pricing & redistribution terms are very reasonable, but there is still a cost. I'm still not 100% sure if you want to write everything yourself in VB6 or if you are willing to use paid/other third-party libraries in your project? If you are open to using paid/third-party libraries, I have a license for the Chilkat bundle so I can give it a try to see if I can get things working.
    Yeah if it works, it works. I'm open to paid or other third party libraries. Zero percent chance I can code anything crypto from the ground up. Terrible at cryptography, mediocre at VB6. But I am good at web emulation programming, speed optimization, arrays, etc. Once I knock out the crypto I think I'll be off to the races and developing unique features very quickly.

    Quote Originally Posted by dilettante View Post
    I don't know what those keys and signatures need to be so I'm not sure whether this helps. I haven't had to revisit it seriously in a long time so the details are murky right now too: RSA Data Signing via CNG.

    By working with the APIs instead of wrappers like CAPICOM you do more work but you also get finer control if required.
    Yeah. As I said before I'll work with anything that works consistently and is up to SHA256 standards. With proper key generation. But at the same time I just want to proof of concept this thing and tune it up later by reprogramming it ground up.

    Quote Originally Posted by couttsj View Post
    When looking at third party solutions, keep in mind that the only thing considered secure these days is TLS 1.2 or better.

    J.A. Coutts
    Yeah I'm apparently trying to use secp256r1 from within Chilkat.

    ##########################################

    Aaanyway,

    I need to figure out how to create and retrieve 64 character sha256 hashes.

    I've been experimenting with Chilkat features. I think I'm almost there.

    I need to use them for digital signatures primarily; e.g. Bob signs a digital signature with his private key and signals it to the blockchain network, they form consensus that Bob does own the private key, based on being able to decrypt his message with his public key, allowing miners or network operators to positively ID the client.

    I've been messing with these

    1. Generate an ECC Key (Public and Private)
    https://www.example-code.com/vb6/ecc...PrivateKey.asp

    2. ECDSA Sign Data and Verify Signature
    https://www.example-code.com/vb6/ecdsa_sign_data.asp

    3. Generate ECDSA Key and Get Details as XML
    https://www.example-code.com/vb6/ecc_genkey_xml.asp

    Number 2 is what I'm most interested in since I am working on a blockchain. Number 3 is in a close second because it appears to allow me to convert keys to .xml and then to 64chr hex. I'd like to replicate this and have it work in tandem with everything else I need to do, e.g. digital signatures etc.

    I think I'm able to turn .pem into SHA256 HEX with the following code for the private key, but I'm not sure if it loses its mathematical relationship with the public key, that I'm apparently not sure how to also produce as 64chr HEX for that is mathematically associated and usable for cryptographically signing data.



    Proof of private key ownership in practice, meaning keypairs are mathematically linked to prove that one person owns both, seems like something I'll need to figure out with a foundation that I understand better. That foundation appears to be.. basic cryptography in VB6 with Chilkat.

    As of now it's only a matter of generating secp256r1 SHA256 keypairs or whatever that are returned in Hex rather than "---PUBLIC KEY STARTING HERE--" huffin and puffin around.

    tl;dr coding a blockchain, not sure how to make chilkat reliably produce ecc/secp256k1/sha256/whatever keypairs in hex, nor am I sure if digital signatures that prove ownership of a public key's private key by working with traditional hex keypairs as seen with Bitcoin

    So, at a brick wall.

    This seems to be the biggest hurdle. Last one, probably.

    Here's some code and source.

    Code:
    Private Sub cmdGenPvt_Click()
    
    'activate
        cActivate
    'entropy
        Dim Fortuna As New ChilkatPrng
        Dim sEntropy As String
        sEntropy = Fortuna.GetEntropy(32, "base64")
        Dim lSuccess As Long
        lSuccess = Fortuna.AddEntropy(sEntropy, "base64")
    'load ecc
        Dim ecc As New ChilkatEcc
    'generate random private key on the bitcoin curve
        Dim privKey As PrivateKey
        Set privKey = ecc.GenEccKey("secp256r1", Fortuna)
        If (ecc.LastMethodSuccess = 0) Then
            Debug.Print ecc.LastErrorText
            Exit Sub
        End If
    'save private key pkcs8 encrypted pem file
        lSuccess = privKey.SavePkcs8EncryptedPemFile("blockchain", "d:\crypto\privatekey.txt")
        If (lSuccess <> 1) Then
            Debug.Print privKey.LastErrorText
        End If
    'extract the public key
        Dim pubKey As publicKey
        Set pubKey = privKey.GetPublicKey()
        ' Save the public key to a PEM file.
        ' (The public key can be saved in a variety of different formats. See the online reference documentation.)
        ' For ECC keys, the 1st argument (bPreferPkcs1) is ignored and unused.
            Dim bPreferPkcs1 As Long
            bPreferPkcs1 = 0
            lSuccess = pubKey.SavePemFile(bPreferPkcs1, "d:\crypto\publickey.txt")
        'set textboxes
            txtPrivateKey.Text = FileText("d:\crypto\privatekey.txt")
            txtPublicKey.Text = FileText("d:\crypto\publickey.txt")
    'display private key in hex
        Dim asn As New ChilkatAsn
        lSuccess = asn.LoadEncoded(privKey.GetPkcs1ENC("base64"), "base64")
        If (lSuccess <> 1) Then
            Debug.Print asn.LastErrorText
            Exit Sub
        End If
        Dim xml As New ChilkatXml
        lSuccess = xml.LoadXml(asn.AsnToXml())
        Debug.Print xml.GetXml()
        '  The 32-byte private key is in the octets..
        '  Get it as hex.
        Dim crypt As New ChilkatCrypt2
        Dim privKeyHex As String
        privKeyHex = crypt.ReEncode(xml.GetChildContent("octets"), "base64", "hex")
        txtPrivateKey.Text = privKeyHex
    'display public key in hex?
        Dim asn2 As New ChilkatAsn
        lSuccess = asn2.LoadEncoded(pubKey.GetPkcs1ENC("base64"), "base64")
        If (lSuccess <> 1) Then
            Debug.Print asn2.LastErrorText
            Exit Sub
        End If
        Dim xml2 As New ChilkatXml
        lSuccess = xml2.LoadXml(asn2.AsnToXml())
        Debug.Print xml2.GetXml()
        '  The 32-byte private key is in the octets..
        '  Get it as hex.
        Dim crypt2 As New ChilkatCrypt2
        Dim pubKeyHex As String
        pubKeyHex = crypt.ReEncode(xml2.GetChildContent("octets"), "base64", "hex")
        'txtPublicKey.Text = pubKeyHex
    
    End Sub
    It's 10AM and I'm still awake so pardon any scatterbrained delivery. I even had a dream about public key cryptography the other night. This thing is getting programmed whether I kinda suck at VB6 and definitely suck at crypto or not.

    I've updated the thread to contain another $25 BTC bounty. I know it isn't much but I appreciate the time you guys spend helping others. I always learn here.

    It is using the 32bit Chilkat .dll if anyone wants to take a look. `cActivate` in `Form_Load` calls a module that is attached in the .zip at the bottom, but is just unlock Chilkat's 30 day demo.

    Dim glob As New ChilkatGlobal
    Dim success As Long
    success = glob.UnlockBundle("*")
    If I happen to get this working all in order it's something I'll purchase.

    and I'm so overdue for this type of knowledge. I've just never needed to program with it before.

    But the foundation is laid, sloppily, and I do think will be tied up into a nice interface with surprising performance metrics in the world of blockchain. Eventually.

    I've been running a bunch of experiments. I'm definitely committed to finishing this thing with a lot of bells and whistles that blockchain hasn't seen. I don't think it's the most impressive technology out there but I definitely think there should be demos of alternate economic models, account recovery procedures and a handful of useful applications.



    Here's just the keypair generator, the most recent of my toiling about. It is referenced in the source and screen shot above.

    I don't care what type of code is used, third party or not, as long as hex sha256 hashes are able to be used to verify ownership of public keys.

    I can't find any extremely simple examples with easy to use functions with documentation, based on my ability to interpret, that allows for this specific task gracefully.
    Attached Files Attached Files
    Last edited by backflip; Today at 09:30 AM.

  6. #6
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,323

    Re: VB6 Blockchain Public Key Crypto & Digital Signatures & _ $25 BTC Bounty When Sol

    Chilkat has a bunch of methods suffixed with "ENC", and these methods let you specify an encoding such as "hex". So for example, instead of saving your private and public keys to a file then loading then back and trying to convert them to hex, you can use the GetPkcs8ENC or GetPkcs8ENC methods.

    For the private key for example:

    Code:
    Me.txtPrivateKey.Text = privKey.GetPkcs8EncryptedENC("hex", "blockchain")   ' Hex encoding, password="blockchain"
    For the public key
    Me.txtPublicKey.Text = pubKey.GetPkcs8ENC("hex")
    Code:
    
    I'm still digesting the rest of your post to see if I can help with the digital signing + verification stuff.

  7. #7

    Thread Starter
    Member backflip's Avatar
    Join Date
    Oct 2013
    Posts
    42

    Re: VB6 Blockchain Public Key Crypto & Digital Signatures & _ $25 BTC Bounty When Sol

    Quote Originally Posted by jpbro View Post
    Chilkat has a bunch of methods suffixed with "ENC", and these methods let you specify an encoding such as "hex". So for example, instead of saving your private and public keys to a file then loading then back and trying to convert them to hex, you can use the GetPkcs8ENC or GetPkcs8ENC methods.

    For the private key for example:

    Code:
    Me.txtPrivateKey.Text = privKey.GetPkcs8EncryptedENC("hex", "blockchain")   ' Hex encoding, password="blockchain"
    For the public key
    Me.txtPublicKey.Text = pubKey.GetPkcs8ENC("hex")
    Code:
    
    I'm still digesting the rest of your post to see if I can help with the digital signing + verification stuff.
    Well this appears to make it a heck of a lot more uniform. Thank you.

    txtPrivateKey.Text = privKey.GetPkcs8EncryptedENC("hex", "") ' Hex encoding, i removed the password that was "blockchain" because idk if it needs to be here
    txtPublicKey.Text = pubKey.GetPkcs8ENC("hex")
    Name:  dFQMDPH.png
Views: 20
Size:  16.8 KB

    I just don't know why they aren't 64 digits like a regular sha256 or how to get them there.

    Encoding itself much less cryptography are two areas i almost never encounter. I'm a learn as I need to and as I go programmer. This may be illustrated by my having used VB6 almost exclusively, and relatively infrequently, for the past 15+ years. But like many here I see few reasons to switch languages anyhow. That said, if we assume VB6-chain is to be embraced by the masses and become the 1 in 5,000 cryptocurrency that is loved by all (this is sarcasm) and it may need to be ported to a lower level language to better accommodate its zealous irrational fanfare. One can dream.
    Last edited by backflip; Today at 10:10 AM.

  8. #8
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,688

    Re: VB6 Blockchain Public Key Crypto & Digital Signatures & _ $25 BTC Bounty When Sol

    I use Chilkat at work and its been good for over a year. Its definitely worth the money. You dont want to be reinventing the wheel and risk creating issues.
    They have several examples on their site and do provide support, if you have actually purchased the library
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,323

    Re: VB6 Blockchain Public Key Crypto & Digital Signatures & _ $25 BTC Bounty When Sol

    I've modified your sample code to generate HEX private/public keys and I've included Sign & Verify buttons.

    keypairGeneratorzip.zip

  10. #10
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,323

    Re: VB6 Blockchain Public Key Crypto & Digital Signatures & _ $25 BTC Bounty When Sol

    Quote Originally Posted by RobDog888 View Post
    I use Chilkat at work and its been good for over a year. Its definitely worth the money. You dont want to be reinventing the wheel and risk creating issues.
    They have several examples on their site and do provide support, if you have actually purchased the library
    +1 to the Chilkat recommendation. It's a great bundle for a reasonable price and the support has always been excellent when I've needed it.

  11. #11
    Frenzied Member
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    1,323

    Re: VB6 Blockchain Public Key Crypto & Digital Signatures & _ $25 BTC Bounty When Sol

    Just noticed a bug in the demo code I provided. In the cmdVerifyString_Click() event, the code for loading the public key should be changed to this:

    Code:
       If lo_PublicKey.LoadFromBinary(lo_PublicKeyBd.GetBinary) <> 1 Then Err.Raise vbObjectError, , "Could not load public key!"  ' Load public key binary data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width