You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2.`mode` — "rsa-pkcs1" for PKCS#1padding, or "rsa" if you know what you're doing.
455
+
2.`mode` — "rsa-sha1", "rsa-sha256", "rsa-sha384", or "rsa-sha512" for RSA-OAEP with the corresponding hash, "rsa-pkcs1" for PKCS#1v1.5, or "rsa" if you know what you're doing.
456
456
3.`key` — The public or private key to use. Commonly, a public key is used to encrypt data.
457
+
4.`label` — *(optional)* Associated data/label used for RSA-OAEP. Must match between encryption and decryption.
457
458
### `crypto.decrypt`
458
459
#### Parameters
459
460
1.`data` — The ciphertext to decrypt.
460
-
2.`mode` — "rsa-pkcs1" for PKCS#1padding, or "rsa" if you know what you're doing.
461
+
2.`mode` — "rsa-sha1", "rsa-sha256", "rsa-sha384", or "rsa-sha512" for RSA-OAEP with the corresponding hash, "rsa-pkcs1" for PKCS#1v1.5, or "rsa" if you know what you're doing.
461
462
3.`key` — The public or private key to use. If the data was encrypted with the public key, the private key is needed to decrypt it.
463
+
4.`label` — *(optional)* Associated data/label used for RSA-OAEP. Must match what was provided during encryption.
462
464
```pluto
463
465
local { base64, bigint, crypto } = require "pluto:*"
464
466
local priv = {
465
467
p = new bigint("115443384115231951475820445136871322101870729500298182134363293112660251666017"),
466
468
q = new bigint("98365361248415863235179644468056200977592391948608651522703704315152579004021"),
467
469
}
468
-
-- Derive public key
469
-
local pub = {
470
-
n = priv.p * priv.q, -- 11355630182234424425429331560518598643298965915936825610957270519615363349759012613228119611304846673085167794661819394470107090216347491908311079792054357
471
-
e = new bigint(0x10001) -- 65537
472
-
}
470
+
local pub = crypto.derive("rsa", priv)
473
471
-- Encrypt
474
-
local enc = crypto.encrypt("A secret message to the owner of the private key.", "rsa-pkcs1", pub)
472
+
local enc = crypto.encrypt("You know the primes!", "rsa-sha1", pub, "Authenticated Data")
475
473
print(base64.encode(enc))
476
474
-- Decrypt
477
-
print(enc |> crypto.decrypt|"rsa-pkcs1", priv|) --> A secret message to the owner of the private key.
475
+
print(enc |> crypto.decrypt|"rsa-sha1", priv, "Authenticated Data"|) --> You know the primes!
0 commit comments