Example #1
0
def encode_private_key(
        key: ec.EllipticCurvePrivateKeyWithSerialization) -> bytes:
    return key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.TraditionalOpenSSL,
        encryption_algorithm=serialization.NoEncryption(),
    )
Example #2
0
def get_private_key_bytes(
    private_key: ec.EllipticCurvePrivateKeyWithSerialization,
    encoding: Encoding = Encoding.DER,
    format: PrivateFormat = PrivateFormat.PKCS8,
    encryption_algorithm: KeySerializationEncryption = NoEncryption()
) -> bytes:
    """ Returns the bytes from a cryptography ec.EllipticCurvePrivateKey
    """
    return private_key.private_bytes(encoding=encoding,
                                     format=format,
                                     encryption_algorithm=encryption_algorithm)
Example #3
0
def encode_key(key: ec.EllipticCurvePrivateKeyWithSerialization) -> str:
    """ Returns the key as a PEM formatted string """
    return key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.PKCS8,
        encryption_algorithm=serialization.NoEncryption()).decode("ascii")
Example #4
0
def get_node_tls_key_pem(
        key: ec.EllipticCurvePrivateKeyWithSerialization) -> str:
    b = key.private_bytes(encoding=serialization.Encoding.PEM,
                          format=serialization.PrivateFormat.PKCS8,
                          encryption_algorithm=serialization.NoEncryption())
    return b.decode('ascii')
Example #5
0
def serialize_key(key: EllipticCurvePrivateKeyWithSerialization) -> str:
    return key.private_bytes(Encoding.PEM, PrivateFormat.TraditionalOpenSSL,
                             NoEncryption()).decode("utf-8")