--mimepart_4d62f6f3b74_1dc2ab0fc16330e0
Content-Type: text/plain
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

Feature #4423: [ext/openssl] Allow encryption for PEM-encoding Elliptic Curve private keys
http://redmine.ruby-lang.org/issues/show/4423

Author: Martin Bosslet
Status: Open, Priority: Normal
Category: ext, Target version: 1.9.3

There has already been some #if 0-excluded code that would actually
take care of this, but it has not been implemented yet. The attached atch allows to encrypt PEM-encoded private keys, Cipher and password
are ignored in the case of public keys (rather than raising an error).

The motivation for this patch is that it would provide uniform behavior f all three public key systems supported in Ruby, RSA, DSA (who already
support PEM encryption) and now also Elliptic Curve. RDoc has been upplemented.

Regards,
Martin


----------------------------------------
http://redmine.ruby-lang.org

--mimepart_4d62f6f3b74_1dc2ab0fc16330e0
Content-Type: text/x-patch; name=ec_pem_pwd.diff
Content-Transfer-Encoding: Base64
Content-Disposition: attachment; filename=ec_pem_pwd.diff

SW5kZXg6IHJ1YnkvZXh0L29wZW5zc2wvb3NzbF9wa2V5X2VjLmMKPT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PQotLS0gcnVieS9leHQvb3BlbnNzbC9vc3NsX3Br
ZXlfZWMuYwkocmV2aXNpb24gMzA5MzgpCisrKyBydWJ5L2V4dC9vcGVuc3Ns
L29zc2xfcGtleV9lYy5jCSh3b3JraW5nIGNvcHkpCkBAIC00NTcsMTYgKzQ1
NywxMyBAQAogICAgIHJldHVybiAoRUNfS0VZX2dldDBfcHJpdmF0ZV9rZXko
ZWMpID8gUXRydWUgOiBRZmFsc2UpOwogfQogCi1zdGF0aWMgVkFMVUUgb3Nz
bF9lY19rZXlfdG9fc3RyaW5nKFZBTFVFIHNlbGYsIGludCBmb3JtYXQpCitz
dGF0aWMgVkFMVUUgb3NzbF9lY19rZXlfdG9fc3RyaW5nKFZBTFVFIHNlbGYs
IFZBTFVFIGNpcGgsIFZBTFVFIHBhc3MsIGludCBm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