Skip to content

Instantly share code, notes, and snippets.

@Zfinix
Last active March 26, 2020 13:00
Show Gist options
  • Select an option

  • Save Zfinix/915c8260ad6da0c5746ae510710339d4 to your computer and use it in GitHub Desktop.

Select an option

Save Zfinix/915c8260ad6da0c5746ae510710339d4 to your computer and use it in GitHub Desktop.
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