pyndn.encrypt.algo package
Submodules
pyndn.encrypt.algo.aes_algorithm module
This module defines the AesAlgorithm class which provides static methods to
manipulate keys, encrypt and decrypt using the AES symmetric key cipher.
Note: This class is an experimental feature. The API may change.
-
class pyndn.encrypt.algo.aes_algorithm.AesAlgorithm[source]
Bases: object
-
BLOCK_SIZE = 16
-
static decrypt(keyBits, encryptedData, params)[source]
Decrypt the encryptedData using the keyBits according the encrypt params.
Parameters: |
- keyBits (Blob) – The key value.
- encryptedData (Blob) – The data to decrypt.
- params (EncryptParams) – This decrypts according to
params.getAlgorithmType() and other params as needed such as
params.getInitialVector().
|
Returns: | The decrypted data.
|
Return type: | Blob
|
-
static deriveEncryptKey(keyBits)[source]
Derive a new encrypt key from the given decrypt key value.
Parameters: | keyBits (Blob) – The key value of the decrypt key. |
Returns: | The new encrypt key. |
Return type: | EncryptKey |
-
static encrypt(keyBits, plainData, params)[source]
Encrypt the plainData using the keyBits according the encrypt params.
Parameters: |
- keyBits (Blob) – The key value.
- plainData (Blob) – The data to encrypt.
- params (EncryptParams) – This encrypts according to
params.getAlgorithmType() and other params as needed such as
params.getInitialVector().
|
Returns: | The encrypted data.
|
Return type: | Blob
|
-
static generateKey(params)[source]
Generate a new random decrypt key for AES based on the given params.
Parameters: | params (AesKeyParams) – The key params with the key size (in bits). |
Returns: | The new decrypt key. |
Return type: | DecryptKey |
pyndn.encrypt.algo.encrypt_params module
This module defines the EncryptParams class which holds an algorithm type and
other parameters used to encrypt and decrypt.
Note: This class is an experimental feature. The API may change.
-
class pyndn.encrypt.algo.encrypt_params.EncryptAlgorithmType[source]
Bases: object
-
AesCbc = 1
-
AesEcb = 0
-
RsaOaep = 3
-
RsaPkcs = 2
-
class pyndn.encrypt.algo.encrypt_params.EncryptParams(algorithmType, initialVectorLength=None)[source]
Bases: object
Create an EncryptParams with the given parameters.
Parameters: |
- algorithmType (int) – The algorithm type from EncryptAlgorithmType, or
None if not specified.
- initialVectorLength (int) – (optional) The initial vector length, or 0
if the initial vector is not specified. If ommitted, the initial vector is
not specified.
|
-
getAlgorithmType()[source]
Get the algorithmType.
Returns: | The algorithm type from EncryptAlgorithmType, or None if not
specified. |
Return type: | int |
-
getInitialVector()[source]
Get the initial vector.
Returns: | The initial vector. If not specified, isNull() is true. |
Return type: | Blob |
-
setAlgorithmType(algorithmType)[source]
Set the algorithm type.
Parameters: | algorithmType (int) – The algorithm type from EncryptAlgorithmType.
If not specified, set to None. |
Returns: | This EncryptParams so that you can chain calls to update values. |
Return type: | EncryptParams |
-
setInitialVector(initialVector)[source]
Set the initial vector.
Parameters: | initialVector (Blob) – The initial vector. If not specified, set to
the default Blob() where isNull() is True. |
Returns: | This EncryptParams so that you can chain calls to update values. |
Return type: | EncryptParams |
pyndn.encrypt.algo.encryptor module
This module defines the Encryptor class which has static constants and utility
methods for encryption, such as encryptData.
Note: This class is an experimental feature. The API may change.
-
class pyndn.encrypt.algo.encryptor.Encryptor[source]
Bases: object
-
NAME_COMPONENT_ACCESS = <pyndn.name.Component object at 0x45ee190>
-
NAME_COMPONENT_C_KEY = <pyndn.name.Component object at 0x45ee390>
-
NAME_COMPONENT_D_KEY = <pyndn.name.Component object at 0x45ee890>
-
NAME_COMPONENT_E_KEY = <pyndn.name.Component object at 0x45ee6d0>
-
NAME_COMPONENT_FOR = <pyndn.name.Component object at 0x45ee810>
-
NAME_COMPONENT_READ = <pyndn.name.Component object at 0x45ee850>
-
NAME_COMPONENT_SAMPLE = <pyndn.name.Component object at 0x45ee790>
-
PyCryptoUsesStr = True
-
static encryptData(data, payload, keyName, key, params)[source]
Prepare an encrypted data packet by encrypting the payload using the key
according to the params. In addition, this prepares the encoded
EncryptedContent with the encryption result using keyName and params.
The encoding is set as the content of the data packet. If params defines
an asymmetric encryption algorithm and the payload is larger than the
maximum plaintext size, this encrypts the payload with a symmetric key
that is asymmetrically encrypted and provided as a nonce in the content
of the data packet. The packet’s <dataName>/ is updated to be
<dataName>/FOR/<keyName>
Parameters: |
- data (Data) – The data packet which is updated.
- payload (Blob) – The payload to encrypt.
- keyName (Name) – The key name for the EncryptedContent.
- key (Blob) – The encryption key value.
- params (EncryptParams) – The parameters for encryption.
|
-
static toPyCrypto(blob)[source]
Convert the blob to an input buffer for PyCrypto.
Parameters: | blob (Blob) – The blob to convert. |
Returns: | The input buffer for PyCrypto |
Return type: | raw string or bytearray |
pyndn.encrypt.algo.rsa_algorithm module
This module defines the RsaAlgorithm class which provides static methods to
manipulate keys, encrypt and decrypt using RSA.
-
class pyndn.encrypt.algo.rsa_algorithm.RsaAlgorithm[source]
Bases: object
-
RSA_ENCRYPTION_OID = '1.2.840.113549.1.1.1'
-
static decrypt(keyBits, encryptedData, params)[source]
Decrypt the encryptedData using the keyBits according the encrypt params.
Parameters: |
- keyBits (Blob) – The key value (PKCS8-encoded private key).
- encryptedData (Blob) – The data to decrypt.
- params (EncryptParams) – This decrypts according to
params.getAlgorithmType().
|
Returns: | The decrypted data.
|
Return type: | Blob
|
-
static deriveEncryptKey(keyBits)[source]
Derive a new encrypt key from the given decrypt key value.
Parameters: | keyBits (Blob) – The key value of the decrypt key (PKCS8-encoded
private key). |
Returns: | The new encrypt key (DER-encoded public key). |
Return type: | EncryptKey |
-
static encrypt(keyBits, plainData, params)[source]
Encrypt the plainData using the keyBits according the encrypt params.
Parameters: |
- keyBits (Blob) – The key value (DER-encoded public key).
- plainData (Blob) – The data to encrypt.
- params (EncryptParams) – This encrypts according to
params.getAlgorithmType().
|
Returns: | The encrypted data.
|
Return type: | Blob
|
-
static generateKey(params)[source]
Generate a new random decrypt key for RSA based on the given params.
Parameters: | params (RsaKeyParams) – The key params with the key size (in bits). |
Returns: | The new decrypt key (PKCS8-encoded private key). |
Return type: | DecryptKey |
Module contents