The data to encrypt (string or Blob)
The recipient's public key in hexadecimal format
The platform adapter providing cryptographic operations
Promise resolving to the encrypted data as a string
This function implements asymmetric encryption using the recipient's public key, enabling secure data sharing where only the holder of the corresponding private key can decrypt the data. It automatically handles different data types and uses platform-appropriate cryptographic libraries for maximum compatibility.
This is commonly used when granting permissions to applications or servers, where the data needs to be encrypted for a specific recipient's public key.
// Encrypt data for a specific application's public key
const appPublicKey = "0x04a1b2c3..."; // Application's public key
const sensitiveData = "User's private information";
const encrypted = await encryptWithWalletPublicKey(
sensitiveData,
appPublicKey,
platformAdapter
);
console.log('Encrypted for app:', encrypted);
// Encrypt file data for server processing
const fileBlob = new File(['{"name":"John","age":30}'], 'profile.json');
const encryptedFile = await encryptWithWalletPublicKey(
fileBlob,
serverPublicKey,
platformAdapter
);
Encrypts data using a wallet's public key for secure sharing with specific recipients.