|
12 | 12 | # This is used to translate between the curve representation in |
13 | 13 | # Cryptography and the one used by NIST (and in RFC 7518) |
14 | 14 | NIST2SEC = { |
| 15 | + 'B-571': ec.SECT571R1, |
15 | 16 | 'K-571': ec.SECT571K1, |
16 | 17 | 'K-409': ec.SECT409K1, |
17 | 18 | 'K-283': ec.SECT283K1, |
@@ -59,40 +60,40 @@ def ec_construct_private(num): |
59 | 60 | return priv_ecpn.private_key(default_backend()) |
60 | 61 |
|
61 | 62 |
|
62 | | -# def import_private_key_from_file(filename, passphrase=None): |
63 | | -# """ |
64 | | -# Read a private Elliptic Curve key from a PEM file. |
65 | | -# |
66 | | -# :param filename: The name of the file |
67 | | -# :param passphrase: A pass phrase to use to unpack the PEM file. |
68 | | -# :return: A |
69 | | -# cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey |
70 | | -# instance |
71 | | -# """ |
72 | | -# with open(filename, "rb") as key_file: |
73 | | -# private_key = serialization.load_pem_private_key( |
74 | | -# key_file.read(), |
75 | | -# password=passphrase, |
76 | | -# backend=default_backend()) |
77 | | -# |
78 | | -# return private_key |
79 | | -# |
80 | | -# |
81 | | -# def import_public_key_from_file(filename): |
82 | | -# """ |
83 | | -# Read a public Elliptic Curve key from a PEM file. |
84 | | -# |
85 | | -# :param filename: The name of the file |
86 | | -# :param passphrase: A pass phrase to use to unpack the PEM file. |
87 | | -# :return: A |
88 | | -# cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey |
89 | | -# instance |
90 | | -# """ |
91 | | -# with open(filename, "rb") as key_file: |
92 | | -# public_key = serialization.load_pem_public_key( |
93 | | -# key_file.read(), |
94 | | -# backend=default_backend()) |
95 | | -# return public_key |
| 63 | +def import_private_key_from_file(filename, passphrase=None): |
| 64 | + """ |
| 65 | + Read a private Elliptic Curve key from a PEM file. |
| 66 | +
|
| 67 | + :param filename: The name of the file |
| 68 | + :param passphrase: A pass phrase to use to unpack the PEM file. |
| 69 | + :return: A |
| 70 | + cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey |
| 71 | + instance |
| 72 | + """ |
| 73 | + with open(filename, "rb") as key_file: |
| 74 | + private_key = serialization.load_pem_private_key( |
| 75 | + key_file.read(), |
| 76 | + password=passphrase, |
| 77 | + backend=default_backend()) |
| 78 | + |
| 79 | + return private_key |
| 80 | + |
| 81 | + |
| 82 | +def import_public_key_from_file(filename): |
| 83 | + """ |
| 84 | + Read a public Elliptic Curve key from a PEM file. |
| 85 | +
|
| 86 | + :param filename: The name of the file |
| 87 | + :param passphrase: A pass phrase to use to unpack the PEM file. |
| 88 | + :return: A |
| 89 | + cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey |
| 90 | + instance |
| 91 | + """ |
| 92 | + with open(filename, "rb") as key_file: |
| 93 | + public_key = serialization.load_pem_public_key( |
| 94 | + key_file.read(), |
| 95 | + backend=default_backend()) |
| 96 | + return public_key |
96 | 97 |
|
97 | 98 |
|
98 | 99 | class ECKey(AsymmetricKey): |
@@ -242,13 +243,13 @@ def load_key(self, key): |
242 | 243 |
|
243 | 244 | return self |
244 | 245 |
|
245 | | - # def load(self, filename): |
246 | | - # """ |
247 | | - # Load an Elliptic curve key from a file. |
248 | | - # |
249 | | - # :param filename: File name |
250 | | - # """ |
251 | | - # return self.load_key(import_private_key_from_file(filename)) |
| 246 | + def load(self, filename): |
| 247 | + """ |
| 248 | + Load an Elliptic curve key from a file. |
| 249 | +
|
| 250 | + :param filename: File name |
| 251 | + """ |
| 252 | + return self.load_key(import_private_key_from_file(filename)) |
252 | 253 |
|
253 | 254 | def decryption_key(self): |
254 | 255 | """ |
|
0 commit comments