@@ -570,6 +570,7 @@ A module to provide error messages.
570
570
### err.format_error
571
571
572
572
** syntax** : * msg = err.format_error(ctx_msg?, return_code?, all_errors?)*
573
+
573
574
** syntax** : * msg = err.format_all_errors(ctx_msg?, return_code?)*
574
575
575
576
Return the latest error message from the last error code. Errors are formatted as:
@@ -905,6 +906,26 @@ local key, err = pkey.new({
905
906
})
906
907
```
907
908
909
+ It's also possible to pass raw pkeyopt control strings in ` config ` table as used in the ` genpkey ` CLI program.
910
+ See [ openssl-genpkey(1)] ( https://www.openssl.org/docs/man3.0/man1/openssl-genpkey.html ) for a list of options.
911
+
912
+ For example:
913
+
914
+ ``` lua
915
+ pkey .new ({
916
+ type = ' RSA' ,
917
+ bits = 2048 ,
918
+ exp = 65537 ,
919
+ })
920
+ -- is same as
921
+ pkey .new ({
922
+ type = ' RSA' ,
923
+ exp = 65537 ,
924
+ " rsa_keygen_bits:4096" ,
925
+ })
926
+
927
+ ```
928
+
908
929
909
930
[ Back to TOC] ( #table-of-contents )
910
931
@@ -956,6 +977,9 @@ local pem, err = pkey.paramgen({
956
977
})
957
978
```
958
979
980
+ It's also possible to pass raw pkeyopt control strings in ` config ` table as used in the ` genpkey ` CLI program.
981
+ See [ openssl-genpkey(1)] ( https://www.openssl.org/docs/man3.0/man1/openssl-genpkey.html ) for a list of options.
982
+
959
983
[ Back to TOC] ( #table-of-contents )
960
984
961
985
### pkey: get_provider_name
@@ -1110,10 +1134,20 @@ to use when signing. When `md_alg` is undefined, for RSA and EC keys, this funct
1110
1134
by default. For Ed25519 or Ed448 keys, this function does a PureEdDSA signing,
1111
1135
no message digest should be specified and will not be used.
1112
1136
1113
- ` opts ` is a table that accepts additional parameters.
1137
+ For RSA key, it's also possible to specify ` padding ` scheme with following choices:
1114
1138
1115
- For RSA key, it's also possible to specify ` padding ` scheme. The choice of values are same
1116
- as those in [ pkey: encrypt ] ( #pkeyencrypt ) . When ` padding ` is ` RSA_PKCS1_PSS_PADDING ` , it's
1139
+ ``` lua
1140
+ pkey .PADDINGS = {
1141
+ RSA_PKCS1_PADDING = 1 ,
1142
+ RSA_SSLV23_PADDING = 2 ,
1143
+ RSA_NO_PADDING = 3 ,
1144
+ RSA_PKCS1_OAEP_PADDING = 4 ,
1145
+ RSA_X931_PADDING = 5 , -- sign only
1146
+ RSA_PKCS1_PSS_PADDING = 6 , -- sign and verify only
1147
+ }
1148
+ ```
1149
+
1150
+ When ` padding ` is ` RSA_PKCS1_PSS_PADDING ` , it's
1117
1151
possible to specify PSS salt length by setting ` opts.pss_saltlen ` .
1118
1152
1119
1153
For EC key, this function does a ECDSA signing.
@@ -1125,6 +1159,32 @@ is encoded in ASN.1 DER format. If the `opts` table contains a `ecdsa_use_raw` f
1125
1159
a true value, a binary with just the concatenation of binary representation ` pr ` and ` ps ` is returned.
1126
1160
This is useful for example to send the signature as JWS.
1127
1161
1162
+ ` opts ` is a table that accepts additional parameters with following choices:
1163
+
1164
+ ```
1165
+ {
1166
+ pss_saltlen, -- For PSS mode only this option specifies the salt length.
1167
+ mgf1_md, -- For PSS and OAEP padding sets the MGF1 digest. If the MGF1 digest is not explicitly set in PSS mode then the signing digest is used.
1168
+ oaep_md, -- The digest used for the OAEP hash function. If not explicitly set then SHA1 is used.
1169
+ }
1170
+ ```
1171
+
1172
+ It's also possible to pass raw pkeyopt control strings as used in the ` pkeyutl ` CLI program. This lets user pass in options that
1173
+ are not explictly supported as parameters above.
1174
+ See [ openssl-pkeyutl(1)] ( https://www.openssl.org/docs/manmaster/man1/openssl-pkeyutl.html ) for a list of options.
1175
+
1176
+ ``` lua
1177
+ pk :sign (message , nil , pk .PADDINGS .RSA_PKCS1_OAEP_PADDING , {
1178
+ oaep_md = " sha256" ,
1179
+ })
1180
+ -- is same as
1181
+ pk :sign (message , nil , nil , {
1182
+ " rsa_padding_mode:oaep" ,
1183
+ " rsa_oaep_md:sha256" ,
1184
+ })
1185
+ -- in pkeyutl CLI the above is equivalent to: `openssl pkeyutl -sign -pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256
1186
+ ```
1187
+
1128
1188
[ Back to TOC] ( #table-of-contents )
1129
1189
1130
1190
### pkey: verify
@@ -1147,17 +1207,19 @@ to use when verifying. When `md_alg` is undefined, for RSA and EC keys, this fun
1147
1207
by default. For Ed25519 or Ed448 keys, this function does a PureEdDSA verification,
1148
1208
no message digest should be specified and will not be used.
1149
1209
1150
- ` opts ` is a table that accepts additional parameters.
1151
-
1152
- For RSA key, it's also possible to specify ` padding ` scheme. The choice of values are same
1153
- as those in [ pkey: encrypt ] ( #pkeyencrypt ) . When ` padding ` is ` RSA_PKCS1_PSS_PADDING ` , it's
1210
+ When key is a RSA key, the function accepts an optional argument ` padding ` which choices
1211
+ of values are same as those in [ pkey: sign ] ( #pkeysign ) . When ` padding ` is ` RSA_PKCS1_PSS_PADDING ` , it's
1154
1212
possible to specify PSS salt length by setting ` opts.pss_saltlen ` .
1155
1213
1156
1214
For EC key, this function does a ECDSA verification. Normally, the ECDSA signature
1157
1215
should be encoded in ASN.1 DER format. If the ` opts ` table contains a ` ecdsa_use_raw ` field with
1158
1216
a true value, this library treat ` signature ` as concatenation of binary representation ` pr ` and ` ps ` .
1159
1217
This is useful for example to verify the signature as JWS.
1160
1218
1219
+ ` opts ` is a table that accepts additional parameters which choices
1220
+ of values are same as those in [ pkey: sign ] ( #pkeysign ) .
1221
+
1222
+
1161
1223
``` lua
1162
1224
-- RSA and EC keys
1163
1225
local pk , err = require (" resty.openssl.pkey" ).new ()
@@ -1193,34 +1255,28 @@ ngx.say(ngx.encode_base64(signature))
1193
1255
1194
1256
### pkey: encrypt
1195
1257
1196
- ** syntax** : * cipher_txt, err = pk: encrypt (txt, padding?)*
1258
+ ** syntax** : * cipher_txt, err = pk: encrypt (txt, padding?, opts? )*
1197
1259
1198
1260
Encrypts plain text ` txt ` with ` pkey ` instance, which must loaded a public key.
1199
1261
1200
- When key is a RSA key, the function accepts an optional second argument ` padding ` which can be:
1262
+ The optional second argument ` padding ` has same meaning as in [ pkey: sign ] ( #pkeysign ) .
1263
+ If omitted, ` padding ` is default to ` pkey.PADDINGS.RSA_PKCS1_PADDING ` .
1201
1264
1202
- ``` lua
1203
- pkey .PADDINGS = {
1204
- RSA_PKCS1_PADDING = 1 ,
1205
- RSA_SSLV23_PADDING = 2 ,
1206
- RSA_NO_PADDING = 3 ,
1207
- RSA_PKCS1_OAEP_PADDING = 4 ,
1208
- RSA_X931_PADDING = 5 ,
1209
- RSA_PKCS1_PSS_PADDING = 6 ,
1210
- }
1211
- ```
1265
+ The third optional argument ` opts ` has same meaning as in [ pkey: sign ] ( #pkeysign ) .
1212
1266
1213
- If omitted, ` padding ` is default to ` pkey.PADDINGS.RSA_PKCS1_PADDING ` .
1214
1267
1215
1268
[ Back to TOC] ( #table-of-contents )
1216
1269
1217
1270
### pkey: decrypt
1218
1271
1219
- ** syntax** : * txt, err = pk: decrypt (cipher_txt, padding?)*
1272
+ ** syntax** : * txt, err = pk: decrypt (cipher_txt, padding?, opts? )*
1220
1273
1221
1274
Decrypts cipher text ` cipher_txt ` with pkey instance, which must loaded a private key.
1222
1275
1223
- The optional second argument ` padding ` has same meaning in [ pkey: encrypt ] ( #pkeyencrypt ) .
1276
+ The optional second argument ` padding ` has same meaning as in [ pkey: sign ] ( #pkeysign ) .
1277
+ If omitted, ` padding ` is default to ` pkey.PADDINGS.RSA_PKCS1_PADDING ` .
1278
+
1279
+ The third optional argument ` opts ` has same meaning as in [ pkey: sign ] ( #pkeysign ) .
1224
1280
1225
1281
``` lua
1226
1282
local pkey = require (" resty.openssl.pkey" )
@@ -1239,11 +1295,14 @@ ngx.say(decrypted)
1239
1295
1240
1296
### pkey: sign_raw
1241
1297
1242
- ** syntax** : * signature, err = pk: sign_raw (txt, padding?)*
1298
+ ** syntax** : * signature, err = pk: sign_raw (txt, padding?, opts? )*
1243
1299
1244
1300
Signs the cipher text ` cipher_txt ` with pkey instance, which must loaded a private key.
1245
1301
1246
- The optional second argument ` padding ` has same meaning in [ pkey: encrypt ] ( #pkeyencrypt ) .
1302
+ The optional second argument ` padding ` has same meaning as in [ pkey: sign ] ( #pkeysign ) .
1303
+ If omitted, ` padding ` is default to ` pkey.PADDINGS.RSA_PKCS1_PADDING ` .
1304
+
1305
+ The third optional argument ` opts ` has same meaning as in [ pkey: sign ] ( #pkeysign ) .
1247
1306
1248
1307
This function may also be called "private encrypt" in some implementations like NodeJS or PHP.
1249
1308
Do note as the function names suggested, this function is not secure to be regarded as an encryption.
@@ -1257,12 +1316,15 @@ for an example.
1257
1316
1258
1317
### pkey: verify_recover
1259
1318
1260
- ** syntax** : * txt, err = pk: verify_recover (signature, padding?)*
1319
+ ** syntax** : * txt, err = pk: verify_recover (signature, padding?, opts? )*
1261
1320
1262
1321
Verify the cipher text ` signature ` with pkey instance, which must loaded a public key, and also
1263
1322
returns the original text being signed. This operation is only supported by RSA key.
1264
1323
1265
- The optional second argument ` padding ` has same meaning in [ pkey: encrypt ] ( #pkeyencrypt ) .
1324
+ The optional second argument ` padding ` has same meaning as in [ pkey: sign ] ( #pkeysign ) .
1325
+ If omitted, ` padding ` is default to ` pkey.PADDINGS.RSA_PKCS1_PADDING ` .
1326
+
1327
+ The third optional argument ` opts ` has same meaning as in [ pkey: sign ] ( #pkeysign ) .
1266
1328
1267
1329
This function may also be called "public decrypt" in some implementations like NodeJS or PHP.
1268
1330
0 commit comments