Hi guys,
after some medical issues I had some time to use ChatGPT (90%) to create an ECDSA library (compiled from a class based on BouncyCastle)
It only works with B4J (B4A throws errors. Actually BC should work here, too. Will post that topic in the Android forum later)
It supports
- creating ECDSA keypairs (all curves BC supports)
- ex-/importing keys (PEM format)
- ex-/importing encrypted private keys (pkcs8# PEM format)
- creating a shared secret (own private key & remote/foreign public key)
- signing & verifying data
- hashing (all algorythms BC supports)
The lib uses the following BC jars (no need to add them)
bcprov-jdk18on-1.86
bcpkix-jdk18on-1.86
bcutil-jdk18on-1.85
As an extra
- list all curves BC supports
- list all algorythms (like SHA256) BC supports
- hash data with all supported algorythms of BC
- Base64 en-/decode
- Base32 encode (for authenticatior apps or OTP)
- OTP creation
- creating QRCode data for authenticator apps
To get started:
Note: It's a lazy functional example using the B4J app and a PowerShell 7 script as the counterpart just to show how it works. Nothing fancy. I do think that the code is quite clean and easy to read as the functions are mostly one line of code 
Example:
Sub CreateSignature
'Creates a signature from the data with YOUR private key
'The other side can check the data with YOUR public key to ensure it's from you
'Curve AND signature algorythm must be the same!
'Note: The data is automatically hashed with the given algorytm.
Signature=MyECDSA.Sign("hello".GetBytes("UTF8"),"SHA256withECDSA")
Log("Signature: " & Signature)
File.WriteString(File.DirApp & "/B4xKeys","B4XSignature.sig",Signature)
End Sub
1. Unzip the attached file
2. Copy these two files to the additional libs folder
3. Unzip the Example
4. Start the B4J app
The App will copy a PowerShell script to objects/powershell and will prompt a message to start the PS-Script. The B4J stops.
5. Start the PS-Script (Powershell 7+)
from the B4J folder. Don't move it as you have to edit all paths then -> it's good to test the functions against .net
The script creates it's own ECDSA keys and will promt to start the B4J app again. Reason is that both sides depend on each other (e.g. keys/sign/verify/shard secret). The keys must be present at the execution time so every side needs to be started
at least twice (a,b,a,b)
6. Start the B4J app again and after that the PS script (each side has created all the data now like signatures, shared secret) etc.
7. Take a look at the logs (e.g. to compare the shared secret on both sides). Signatures are compared automatically and promted in the logs.
8. When you aren't able to run the PS script search for "set execution policy"
9. I will add some functions to handle certificates in the future (e.g. get public key from certificate), maybe I add RSA & AES (though agrahams lib is perfectly fine for that)
You can use the lib as you wish
Please comment if you have any questions or if you find errors. Please give me some time to answer. No private messages, please. Just post it here.