We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello everyone, I'm using this code from the example, and there is a problem that Russian characters are displayed like this: "Привет - �@825B".
var keyParams = RSAKeyGeneratorParameters(BigInt.from(65537), 2048, 5); var secureRandom = FortunaRandom(); var random = Random.secure(); List<int> seeds = []; for (int i = 0; i < 32; i++) { seeds.add(random.nextInt(255)); } secureRandom.seed(KeyParameter(Uint8List.fromList(seeds))); var rngParams = ParametersWithRandom(keyParams, secureRandom); var k = RSAKeyGenerator(); k.init(rngParams); dynamic keyPair = k.generateKeyPair(); print(RsaKeyHelper().encodePublicKeyToPem(keyPair.publicKey)); print(RsaKeyHelper().encodePrivateKeyToPem(keyPair.privateKey)); AsymmetricKeyParameter<RSAPublicKey> keyParametersPublic = PublicKeyParameter(keyPair.publicKey); var cipher = RSAEngine()..init(true, keyParametersPublic); var cipherText = cipher.process(Uint8List.fromList("hello".codeUnits)); print(cipherText); print("Encrypted: ${String.fromCharCodes(cipherText)}"); AsymmetricKeyParameter<RSAPrivateKey> keyParametersPrivate = PrivateKeyParameter(keyPair.privateKey); cipher.init(false, keyParametersPrivate); var decrypted = cipher.process(cipherText); print("Decrypted: ${String.fromCharCodes(decrypted)}");
I've been racking my head for several hours, does anyone have a ready-made implementation?
The text was updated successfully, but these errors were encountered:
Fixed.
final chars = "Привет! Hello! 🤘🏻😂😌😄🤣✅".codeUnits; // ........................................................................... var keyParams = RSAKeyGeneratorParameters(BigInt.from(65537), 2048, 5); var secureRandom = FortunaRandom(); var random = Random.secure(); List<int> seeds = []; for (int i = 0; i < 32; i++) { seeds.add(random.nextInt(255)); } secureRandom.seed(KeyParameter(Uint8List.fromList(seeds))); var rngParams = ParametersWithRandom(keyParams, secureRandom); var k = RSAKeyGenerator(); k.init(rngParams); dynamic keyPair = k.generateKeyPair(); print(RsaKeyHelper().encodePublicKeyToPem(keyPair.publicKey)); print(RsaKeyHelper().encodePrivateKeyToPem(keyPair.privateKey)); AsymmetricKeyParameter<RSAPublicKey> keyParametersPublic = PublicKeyParameter(keyPair.publicKey); var cipher = RSAEngine()..init(true, keyParametersPublic); var cipherText = cipher.process(Uint8List.fromList([ ...chars.map<List<int>>((ch) => [ch & 0xff, ch >> 8]).expand((i) => i) ])); print("Encrypted: ${String.fromCharCodes(cipherText)}"); AsymmetricKeyParameter<RSAPrivateKey> keyParametersPrivate = PrivateKeyParameter(keyPair.privateKey); cipher.init(false, keyParametersPrivate); var decrypted = cipher.process(cipherText); final original = [ for (var i = 0; i < decrypted.length; i += 2) decrypted[i] | decrypted[i + 1] << 8 ]; print(decrypted); print("Decrypted: ${String.fromCharCodes(original)}");
Sorry, something went wrong.
No branches or pull requests
Hello everyone, I'm using this code from the example,
and there is a problem that Russian characters are displayed like this: "Привет - �@825B".
I've been racking my head for several hours, does anyone have a ready-made implementation?
The text was updated successfully, but these errors were encountered: