-
Notifications
You must be signed in to change notification settings - Fork 1
02. RSA Encryption and Decryption
romantsisyk edited this page Nov 27, 2024
·
2 revisions
RSA is used for asymmetric encryption. Ideal for encrypting small payloads like keys or tokens.
CryptoKit.encryptRSA(data: String, publicKey: String): String
CryptoKit.decryptRSA(data: String, privateKey: String): String
// RSA Encryption
val publicKey = loadPublicKey() // Load your RSA public key
val privateKey = loadPrivateKey() // Load your RSA private key
val data = "Confidential Data"
val encryptedData = CryptoKit.encryptRSA(data, publicKey)
println("Encrypted: $encryptedData")
// RSA Decryption
val decryptedData = CryptoKit.decryptRSA(encryptedData, privateKey)
println("Decrypted: $decryptedData")
- Public and private keys must be PEM-encoded.
- Suitable for encrypting small data only.