I am working on a Flutter app, which creates crypto wallets for users using BIP39 and BIP32. using BIP39 and BIP32 I can create mnemonics, private and public keys for the users.
now it needs to do some asymmetric encryption for app users, which can be done quickly with RSA packages. As my research, for now, RSA only works with keys (called certificate may be) generated by RSA package only.
I want to do this encryption with the user wallet's private public keys generated BIP39 and BIP32. so is there any way I can use these private-public keys instead of the certificate provided by RSA, or I can convert these keys to be useful for encryption
Here is my code which generates private-public keys
import 'package:hex/hex.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:bip32/bip32.dart' as bip32;
createWallet() async {
var mnemonic = bip39.generateMnemonic();
// => 'seed sock milk update focus rotate .....'
String seed = bip39.mnemonicToSeedHex(mnemonic);
// => Uint8List [92, 242, 212, 168, 1..]
bip32.BIP32 nodeFromSeed = bip32.BIP32.fromSeed(HEX.decode(seed));
String privateKey = HEX.encode(nodeFromSeed.privateKey);
// => 0339a36013301597daef41f.....
bip32.BIP32 nodeNeutered = nodeFromSeed.neutered();
String publicKey = HEX.encode(nodeNeutered.publicKey);
// => 02756de182c5dd4b717ea87e693006...
}
What I have tried so far
- I tried to use BIP keys directly and it doesn't work
- I tried to encode the private key to base64 and tried to make certificate manually.
String encoded = base64.encode(utf8.encode(privateKey));
var newPrivateKey = '-----BEGIN RSA PRIVATE KEY-----\n$encoded\n-----END RSA PRIVATE KEY-----';
- I tried to parse the keys using RSA lib and basic_utils / CryptoUtils
dynamic newPrivateKey = crypto.RSAKeyParser().parse(privateKey);
RSAPrivateKey rsaPrivateKeyFromPemPkcs1(String pem);
unfortunately, none of the options worked for me.