Skip to content
New issue

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

RSAKeyParser is not defined in poiintycastle #333

Open
Ali-hashir opened this issue May 8, 2024 · 0 comments
Open

RSAKeyParser is not defined in poiintycastle #333

Ali-hashir opened this issue May 8, 2024 · 0 comments

Comments

@Ali-hashir
Copy link

In following code it gives me error of

The function 'RSAKeyParser' isn't defined.
Try importing the library that defines 'RSAKeyParser', correcting the name to the name of an existing function, or defining a function named 'RSAKeyParser'.dartundefined_function

import 'package:pointycastle/export.dart' as crypto;

String encryptWithPublicKey(String publicKeyPem, String text) {
// Create an RSA public key from the PEM string
crypto.RSAKeyParser keyParser = crypto.RSAKeyParser();
crypto.RSAPublicKey publicKey = keyParser.parse(publicKeyPem) as crypto.RSAPublicKey;

// Configure the OAEP encoder with SHA-256
crypto.OAEPEncoding oaep = crypto.OAEPEncoding(crypto.RSAEngine())
  ..init(true, crypto.PublicKeyParameter<crypto.RSAPublicKey>(publicKey)); // true for encryption

// Convert text to bytes
Uint8List data = Uint8List.fromList(utf8.encode(text));

// Encrypt the data
Uint8List encrypted = oaep.process(data);

// Encode encrypted bytes to base64
return base64Encode(encrypted);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant