Package dkim :: Module crypto
[hide private]
[frames] | no frames]

Module crypto

source code

Classes [hide private]
  DigestTooLargeError
The digest is too large to fit within the requested length.
  UnparsableKeyError
The data could not be parsed as a key.
Functions [hide private]
 
parse_public_key(data)
Parse an RSA public key.
source code
 
parse_private_key(data)
Parse an RSA private key.
source code
 
parse_pem_private_key(data)
Parse a PEM RSA private key.
source code
 
EMSA_PKCS1_v1_5_encode(hash, mlen)
Encode a digest with RFC8017 EMSA-PKCS1-v1_5.
source code
 
str2int(s)
Convert a byte string to an integer.
source code
 
int2str(n, length=-1)
Convert an integer to a byte string.
source code
 
rsa_decrypt(message, pk, mlen)
Perform RSA decryption/signing
source code
 
rsa_encrypt(message, pk, mlen)
Perform RSA encryption/verification
source code
 
RSASSA_PKCS1_v1_5_sign(hash, private_key)
Sign a digest with RFC8017 RSASSA-PKCS1-v1_5.
source code
 
RSASSA_PKCS1_v1_5_verify(hash, signature, public_key)
Verify a digest signed with RFC8017 RSASSA-PKCS1-v1_5.
source code
Variables [hide private]
  ASN1_Object = [(48, [(48, [(6), (5)]), (3)])]
  ASN1_RSAPublicKey = [(48, [(2), (2)])]
  ASN1_RSAPrivateKey = [(48, [(2), (2), (2), (2), (2), (2), (2),...
  HASH_ALGORITHMS = {'ed25519-sha256': <built-in function openss...
  ARC_HASH_ALGORITHMS = {'rsa-sha256': <built-in function openss...
  HASH_ID_MAP = {'sha1': '+\x0e\x03\x02\x1a', 'sha256': '`\x86H\...
  __package__ = 'dkim'
Function Details [hide private]

parse_public_key(data)

source code 

Parse an RSA public key.

Parameters:
  • data - DER-encoded X.509 subjectPublicKeyInfo containing an RFC8017 RSAPublicKey.
Returns:
RSA public key

parse_private_key(data)

source code 

Parse an RSA private key.

Parameters:
  • data - DER-encoded RFC8017 RSAPrivateKey.
Returns:
RSA private key

parse_pem_private_key(data)

source code 

Parse a PEM RSA private key.

Parameters:
  • data - RFC8017 RSAPrivateKey in PEM format.
Returns:
RSA private key

EMSA_PKCS1_v1_5_encode(hash, mlen)

source code 

Encode a digest with RFC8017 EMSA-PKCS1-v1_5.

Parameters:
  • hash - hash object to encode
  • mlen - desired message length
Returns:
encoded digest byte string

str2int(s)

source code 

Convert a byte string to an integer.

Parameters:
  • s - byte string representing a positive integer to convert
Returns:
converted integer

int2str(n, length=-1)

source code 

Convert an integer to a byte string.

Parameters:
  • n - positive integer to convert
  • length - minimum length
Returns:
converted bytestring, of at least the minimum length if it was specified

rsa_decrypt(message, pk, mlen)

source code 

Perform RSA decryption/signing

Parameters:
  • message - byte string to operate on
  • pk - private key data
  • mlen - desired output length
Returns:
byte string result of the operation

rsa_encrypt(message, pk, mlen)

source code 

Perform RSA encryption/verification

Parameters:
  • message - byte string to operate on
  • pk - public key data
  • mlen - desired output length
Returns:
byte string result of the operation

RSASSA_PKCS1_v1_5_sign(hash, private_key)

source code 

Sign a digest with RFC8017 RSASSA-PKCS1-v1_5.

Parameters:
  • hash - hash object to sign
  • private_key - private key data
Returns:
signed digest byte string

RSASSA_PKCS1_v1_5_verify(hash, signature, public_key)

source code 

Verify a digest signed with RFC8017 RSASSA-PKCS1-v1_5.

Parameters:
  • hash - hash object to check
  • signature - signed digest byte string
  • public_key - public key data
Returns:
True if the signature is valid, False otherwise

Variables Details [hide private]

ASN1_RSAPrivateKey

Value:
[(48, [(2), (2), (2), (2), (2), (2), (2), (2), (2)])]

HASH_ALGORITHMS

Value:
{'ed25519-sha256': <built-in function openssl_sha256>,
 'rsa-sha1': <built-in function openssl_sha1>,
 'rsa-sha256': <built-in function openssl_sha256>}

ARC_HASH_ALGORITHMS

Value:
{'rsa-sha256': <built-in function openssl_sha256>}

HASH_ID_MAP

Value:
{'sha1': '+\x0e\x03\x02\x1a', 'sha256': '`\x86H\x01e\x03\x04\x02\x01'}