Created
September 24, 2024 13:37
-
-
Save brasizza/b51507d6fe6e6305b7e795ccd153a64d to your computer and use it in GitHub Desktop.
This file contains 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
static Future<String> asymmetricEncript(String text) async { | |
String key = ''; | |
if (kIsWeb) { | |
PickedFile localFile = PickedFile('assets/key/pdv.pem'); | |
key = (await localFile.readAsString()); | |
} else { | |
key = await rootBundle.loadString('assets/key/pdv.pem'); | |
} | |
final parser = RSAKeyParser(); | |
final publicKey = parser.parse(key) as RSAPublicKey; | |
final encrypter = Encrypter(RSA(publicKey: publicKey)); | |
final encrypted = encrypter.encrypt(text); | |
return (encrypted.base64); | |
} | |
static Future<String> asymmetricDencript(String text) async { | |
String key = ''; | |
if (kIsWeb) { | |
PickedFile localFile = PickedFile('assets/key/pdv.key'); | |
key = (await localFile.readAsString()); | |
} else { | |
key = await rootBundle.loadString('assets/key/pdv.key'); | |
} | |
final parser = RSAKeyParser(); | |
final private = parser.parse(key) as RSAPrivateKey; | |
final encrypter = Encrypter(RSA(privateKey: private)); | |
final decriptedString = encrypter.decrypt(Encrypted(base64Decode(text))); | |
return (decriptedString); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment