Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

RSAKeyParser is not defined in poiintycastleΒ #333

@Ali-hashir

Description

@Ali-hashir

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);

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions