Skip to content

Commit 38957b2

Browse files
committed
RSA-OAEP
1 parent 204f3ec commit 38957b2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

docs/Runtime Environment/Crypto.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,29 +452,27 @@ ueZ/sI52jgP8+xK2x7coiX5/tDmXCGlp5utUAjk2+Q==
452452
### `crypto.encrypt`
453453
#### Parameters
454454
1. `data` — The data to be encrypted.
455-
2. `mode` — "rsa-pkcs1" for PKCS#1 padding, 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#1 v1.5, or "rsa" if you know what you're doing.
456456
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.
457458
### `crypto.decrypt`
458459
#### Parameters
459460
1. `data` — The ciphertext to decrypt.
460-
2. `mode` — "rsa-pkcs1" for PKCS#1 padding, 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#1 v1.5, or "rsa" if you know what you're doing.
461462
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.
462464
```pluto
463465
local { base64, bigint, crypto } = require "pluto:*"
464466
local priv = {
465467
p = new bigint("115443384115231951475820445136871322101870729500298182134363293112660251666017"),
466468
q = new bigint("98365361248415863235179644468056200977592391948608651522703704315152579004021"),
467469
}
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)
473471
-- 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")
475473
print(base64.encode(enc))
476474
-- 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!
478476
```
479477
### `crypto.sign`
480478
Signs a message as per the PKCS#1 v1.5 scheme.

0 commit comments

Comments
 (0)