Last active
March 26, 2020 13:00
-
-
Save Zfinix/915c8260ad6da0c5746ae510710339d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:secp256k1cipher/secp256k1cipher.dart'; | |
| main() { | |
| var keyPair = generateKeyPair(); | |
| var privKey = keyPair.privateKey; | |
| var pubKey = keyPair.publicKey; | |
| print('Private key: ${strinifyPrivateKey(privKey)}'); | |
| print('Public key: ${strinifyPublicKey(pubKey)}'); | |
| print('Public key length: ${strinifyPublicKey(pubKey).toString().length}'); | |
| var msg = {'amount': 200, 'recipient': "john", 'sender': "joe"}; | |
| var msg2 = json.encode(msg); | |
| var encMap = pubkeyEncrypt( | |
| strinifyPrivateKey(keyPair.privateKey), | |
| strinifyPublicKey(keyPair.publicKey), | |
| msg2); // use alic's privatekey and bob's publickey means alic say to bob | |
| var encStr = encMap['enc']; // Get encrypted base64 string | |
| var iv = encMap['iv']; | |
| var str = ''; | |
| base64Decode(encStr).forEach((v) => str += '$v,'); | |
| print(str); | |
| var decryptd = privateDecrypt( | |
| strinifyPrivateKey(privKey), strinifyPublicKey(pubKey), encStr, iv); | |
| print('Msg: $decryptd'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment