@@ -85,13 +85,13 @@ rsa_generate(int size, int exp)
85
85
}
86
86
87
87
/*
88
- * call-seq:
89
- * RSA.generate(size [, exponent]) -> rsa
90
- *
91
- * === Parameters
92
- * * +size+ is an integer representing the desired key size. Keys smaller than 1024 should be considered insecure.
93
- * * +exponent+ is an odd number normally 3, 17, or 65537.
88
+ * call-seq:
89
+ * RSA.generate(size) => RSA instance
90
+ * RSA.generate(size, exponent) => RSA instance
94
91
*
92
+ * Generates an RSA keypair. +size+ is an integer representing the desired key
93
+ * size. Keys smaller than 1024 should be considered insecure. +exponent+ is
94
+ * an odd number normally 3, 17, or 65537.
95
95
*/
96
96
static VALUE
97
97
ossl_rsa_s_generate (int argc , VALUE * argv , VALUE klass )
@@ -115,18 +115,24 @@ ossl_rsa_s_generate(int argc, VALUE *argv, VALUE klass)
115
115
}
116
116
117
117
/*
118
- * call-seq:
119
- * RSA.new([size | encoded_key] [, pass]) -> rsa
118
+ * call-seq:
119
+ * RSA.new(key_size) => RSA instance
120
+ * RSA.new(encoded_key) => RSA instance
121
+ * RSA.new(encoded_key, pass_phrase) => RSA instance
122
+ *
123
+ * Generates or loads an RSA keypair. If an integer +key_size+ is given it
124
+ * represents the desired key size. Keys less than 1024 bits should be
125
+ * considered insecure.
126
+ *
127
+ * A key can instead be loaded from an +encoded_key+ which must be PEM or DER
128
+ * encoded. A +pass_phrase+ can be used to decrypt the key. If none is given
129
+ * OpenSSL will prompt for the pass phrase.
120
130
*
121
- * === Parameters
122
- * * +size+ is an integer representing the desired key size.
123
- * * +encoded_key+ is a string containing PEM or DER encoded key.
124
- * * +pass+ is an optional string with the password to decrypt the encoded key.
131
+ * = Examples
125
132
*
126
- * === Examples
127
- * * RSA.new(2048) -> rsa
128
- * * RSA.new(File.read("rsa.pem")) -> rsa
129
- * * RSA.new(File.read("rsa.pem"), "mypassword") -> rsa
133
+ * OpenSSL::PKey::RSA.new 2048
134
+ * OpenSSL::PKey::RSA.new File.read 'rsa.pem'
135
+ * OpenSSL::PKey::RSA.new File.read('rsa.pem'), 'my pass phrase'
130
136
*/
131
137
static VALUE
132
138
ossl_rsa_initialize (int argc , VALUE * argv , VALUE self )
@@ -182,11 +188,11 @@ ossl_rsa_initialize(int argc, VALUE *argv, VALUE self)
182
188
}
183
189
184
190
/*
185
- * call-seq:
186
- * rsa.public? -> true
187
- *
188
- * The return value is always true since every private key is also a public key.
191
+ * call-seq:
192
+ * rsa.public? => true
189
193
*
194
+ * The return value is always true since every private key is also a public
195
+ * key.
190
196
*/
191
197
static VALUE
192
198
ossl_rsa_is_public (VALUE self )
@@ -201,9 +207,10 @@ ossl_rsa_is_public(VALUE self)
201
207
}
202
208
203
209
/*
204
- * call-seq:
205
- * rsa.private? - > true | false
210
+ * call-seq:
211
+ * rsa.private? = > true | false
206
212
*
213
+ * Does this keypair contain a private key?
207
214
*/
208
215
static VALUE
209
216
ossl_rsa_is_private (VALUE self )
@@ -216,16 +223,13 @@ ossl_rsa_is_private(VALUE self)
216
223
}
217
224
218
225
/*
219
- * call-seq:
220
- * rsa.to_pem([cipher, pass]) -> aString
221
- *
222
- * === Parameters
223
- * * +cipher+ is a Cipher object.
224
- * * +pass+ is a string.
226
+ * call-seq:
227
+ * rsa.to_pem => PEM-format String
228
+ * rsa.to_pem(cipher, pass_phrase) => PEM-format String
225
229
*
226
- * === Examples
227
- * * rsa.to_pem -> aString
228
- * * rsa.to_pem(cipher, pass) -> aString
230
+ * Outputs this keypair in PEM encoding. If +cipher+ and +pass_phrase+ are
231
+ * given they will be used to encrypt the key. +cipher+ must be an
232
+ * OpenSSL::Cipher::Cipher instance.
229
233
*/
230
234
static VALUE
231
235
ossl_rsa_export (int argc , VALUE * argv , VALUE self )
@@ -267,9 +271,10 @@ ossl_rsa_export(int argc, VALUE *argv, VALUE self)
267
271
}
268
272
269
273
/*
270
- * call-seq:
271
- * rsa.to_der -> aString
274
+ * call-seq:
275
+ * rsa.to_der => DER-format String
272
276
*
277
+ * Outputs this keypair in DER encoding.
273
278
*/
274
279
static VALUE
275
280
ossl_rsa_to_der (VALUE self )
@@ -299,9 +304,12 @@ ossl_rsa_to_der(VALUE self)
299
304
#define ossl_rsa_buf_size (pkey ) (RSA_size((pkey)->pkey.rsa)+16)
300
305
301
306
/*
302
- * call-seq:
303
- * rsa.public_encrypt(string [, padding]) -> aString
307
+ * call-seq:
308
+ * rsa.public_encrypt(string) => String
309
+ * rsa.public_encrypt(string, padding) => String
304
310
*
311
+ * Encrypt +string+ with the public key. +padding+ defaults to PKCS1_PADDING.
312
+ * The encrypted string output can be decrypted using #private_decrypt.
305
313
*/
306
314
static VALUE
307
315
ossl_rsa_public_encrypt (int argc , VALUE * argv , VALUE self )
@@ -325,9 +333,12 @@ ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
325
333
}
326
334
327
335
/*
328
- * call-seq:
329
- * rsa.public_decrypt(string [, padding]) -> aString
336
+ * call-seq:
337
+ * rsa.public_decrypt(string) => String
338
+ * rsa.public_decrypt(string, padding) => String
330
339
*
340
+ * Decrypt +string+, which has been encrypted with the private key, with the
341
+ * public key. +padding+ defaults to PKCS1_PADDING.
331
342
*/
332
343
static VALUE
333
344
ossl_rsa_public_decrypt (int argc , VALUE * argv , VALUE self )
@@ -351,9 +362,12 @@ ossl_rsa_public_decrypt(int argc, VALUE *argv, VALUE self)
351
362
}
352
363
353
364
/*
354
- * call-seq:
355
- * rsa.private_encrypt(string [, padding]) -> aString
365
+ * call-seq:
366
+ * rsa.private_encrypt(string) => String
367
+ * rsa.private_encrypt(string, padding) => String
356
368
*
369
+ * Encrypt +string+ with the private key. +padding+ defaults to PKCS1_PADDING.
370
+ * The encrypted string output can be decrypted using #public_decrypt.
357
371
*/
358
372
static VALUE
359
373
ossl_rsa_private_encrypt (int argc , VALUE * argv , VALUE self )
@@ -379,11 +393,13 @@ ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
379
393
return str ;
380
394
}
381
395
382
-
383
396
/*
384
- * call-seq:
385
- * rsa.private_decrypt(string [, padding]) -> aString
397
+ * call-seq:
398
+ * rsa.private_decrypt(string) => String
399
+ * rsa.private_decrypt(string, padding) => String
386
400
*
401
+ * Decrypt +string+, which has been encrypted with the public key, with the
402
+ * private key. +padding+ defaults to PKCS1_PADDING.
387
403
*/
388
404
static VALUE
389
405
ossl_rsa_private_decrypt (int argc , VALUE * argv , VALUE self )
@@ -410,12 +426,15 @@ ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
410
426
}
411
427
412
428
/*
413
- * call-seq:
414
- * rsa.params - > hash
429
+ * call-seq:
430
+ * rsa.params = > hash
415
431
*
416
- * Stores all parameters of key to the hash
417
- * INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
418
- * Don't use :-)) (I's up to you)
432
+ * THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
433
+ *
434
+ * Stores all parameters of key to the hash. The hash has keys 'n', 'e', 'd',
435
+ * 'p', 'q', 'dmp1', 'dmq1', 'iqmp'.
436
+ *
437
+ * Don't use :-)) (It's up to you)
419
438
*/
420
439
static VALUE
421
440
ossl_rsa_get_params (VALUE self )
@@ -440,11 +459,13 @@ ossl_rsa_get_params(VALUE self)
440
459
}
441
460
442
461
/*
443
- * call-seq:
444
- * rsa.to_text -> aString
462
+ * call-seq:
463
+ * rsa.to_text => String
464
+ *
465
+ * THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!
466
+ *
467
+ * Dumps all parameters of a keypair to a String
445
468
*
446
- * Prints all parameters of key to buffer
447
- * INSECURE: PRIVATE INFORMATIONS CAN LEAK OUT!!!
448
469
* Don't use :-)) (It's up to you)
449
470
*/
450
471
static VALUE
@@ -468,10 +489,10 @@ ossl_rsa_to_text(VALUE self)
468
489
}
469
490
470
491
/*
471
- * call-seq:
472
- * rsa.public_key -> aRSA
492
+ * call-seq:
493
+ * rsa.public_key -> RSA
473
494
*
474
- * Makes new instance RSA PUBLIC_KEY from PRIVATE_KEY
495
+ * Makes new RSA instance containing the public key from the private key.
475
496
*/
476
497
static VALUE
477
498
ossl_rsa_to_public_key (VALUE self )
0 commit comments