Constant-time byte sequence equality.
Good for removing a huge potential timing attack.
Parameters: |
|
---|---|
Return bool: | True if the sequences are the same. |
Raises ValueError: | |
When the byte sequences have different lengths. |
>>> bytes_equal(b'hello', b'hello')
True
>>> bytes_equal(b'hello', b'world')
False
PEM decode a key.
Returns a tuple of:
Throws a tomcrypt.Error if content is not PEM encoded.
PEM encode a key.
Parameters: |
|
---|
>>> print(pem_encode('TEST', 'PRIVATE', b'private content'))
-----BEGIN TEST PRIVATE KEY-----
cHJpdmF0ZSBjb250ZW50
-----END TEST PRIVATE KEY-----
>>> print(pem_encode('TEST', 'PUBLIC', b'public content'))
-----BEGIN PUBLIC KEY-----
cHVibGljIGNvbnRlbnQ=
-----END PUBLIC KEY-----
XOR two sequences of bytes.
Parameters: |
|
---|---|
Return bytes: | A sequence of bytes, the same length of a and b in which each byte is the XOR of the respective bytes from a and b. |
Raises ValueError: | |
When the byte sequences have different lengths. |
>>> xor_bytes(b'hello', b'world')
b'\x1f\n\x1e\x00\x0b'
>>> xor_bytes(b'hello', b'hello')
b'\x00\x00\x00\x00\x00'