1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#!/usr/bin/python3
from ecdsa import SigningKey, NIST384p
import paramiko
from cryptography.hazmat.primitives.serialization import (
Encoding, PrivateFormat, PublicFormat, NoEncryption
)
sk = SigningKey.generate(curve=NIST384p)
sk_string = sk.to_string()
sk2 = SigningKey.from_string(sk_string, curve=NIST384p)
print(sk_string.hex())
print(sk2.to_string().hex())
print("--------------")
pk0 = bytes.fromhex("06cadf8035a6102e6ad0d1ef86c8a68c34a680d5f488d4ba45ef768033ef89ee5f818f4980c2f284c05a176049876ada")
myO = SigningKey.from_string(bytes.fromhex("06cadf8035a6102e6a38d1ef86c8a68c34a680d5ce88d4ba45ef768033ef89ee5f818f4980c2f284c05a176049876ada"), curve=NIST384p);
my0 = SigningKey.from_string(pk0, curve=NIST384p)
print(myO.to_string().hex())
print(my0.to_string().hex())
with open("/tmp/O", "wb") as f:
f.write(myO.to_pem())
print(myO.to_pem())
with open("/tmp/0", "wb") as f:
f.write(my0.to_pem())
print(my0.to_pem())
print("___________");
keyO = paramiko.ECDSAKey.from_private_key_file("/tmp/O")
key0 = paramiko.ECDSAKey.from_private_key_file("/tmp/0")
with open("/tmp/O_ecdsa", "wb") as fh:
data = keyO.signing_key.private_bytes(Encoding.PEM, PrivateFormat.OpenSSH, NoEncryption())
fh.write(data)
with open("/tmp/O_ecdsa.pub", "wb") as fh:
data = keyO.verifying_key.public_bytes(Encoding.OpenSSH, PublicFormat.OpenSSH)
fh.write(data + b"\n")
with open("/tmp/0_ecdsa", "wb") as fh:
data = key0.signing_key.private_bytes(Encoding.PEM, PrivateFormat.OpenSSH, NoEncryption())
fh.write(data)
with open("/tmp/0_ecdsa.pub", "wb") as fh:
data = key0.verifying_key.public_bytes(Encoding.OpenSSH, PublicFormat.OpenSSH)
fh.write(data + b"\n")
|