A DAP.Crypto module is designed to work with encoding binary data to printable ASCII characters and decoding such encodings back to binary data. This module includes the following classes:
DAP.Crypto.Algo
A class for encoding and decoding.DAP.Crypto.Cert
A certificate class.DAP.Crypto.Sign
A sign class.DAP.Crypto.SignType
A sign type class.DAP.Crypto.CryptoKeyType
A key type class.DAP.Crypto.CryptoDataType
A data type classDAP.Crypto.Pkey
A public key class.DAP.Crypto.PkeyType
A public key type class.DAP.Crypto.HashFast
A hash class.class DAP.Crypto.Algo
This class provides encoding and decoding fuctions.
staic method DAP.Crypto.Algo.encodeBase58(buffer: bytes) -> str
Encodes a data using the Base58 algorithm. The buffer
should be a bytes-like object. Returns the encoded string.
staic method DAP.Crypto.Algo.decodeBase58(string: str) -> bytes
Decodes a string using the Base58 algorithm. Returns the decoded bytes.
staic method DAP.Crypto.Algo.encodeBase64(buffer: bytes, typeAlgorithm: int) -> str
Encodes a data using the Base64 algorithm. The buffer
should be a bytes-like object. If the typeAlgorithm
argument is 1
then using the standard Base64 alphabet, if it is 2
using the URL- and filesystem-safe alphabet. Returns the encoded string.
staic method DAP.Crypto.Algo.decodeBase64(string: str, typeAlgorithm: int) -> bytes
Decodes a string using the Base64 algorithm . If the typeAlgorithm
argument is 1
then using the standard Base64 alphabet, if it is 2
using the URL- and filesystem-safe alphabet. Returns the encoded bytes.
staic method DAP.Crypto.Algo.newKey(keyType: int) -> DAP.Crypto.Key
Creates a new key. The keyType
argument defines a type of the new key. Returns the Key
object.
You can find out the value of the keyType
argument using the following methods:
Function | Returned value |
---|---|
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_IAES() |
0 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_OAES() |
1 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_RLWE_NEWHOPE() |
2 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_SIDH_CLN16() |
3 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_DEFEO() |
4 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_MSRLN() |
5 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_MSRLN16() |
6 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_RLWE_BCNS15() |
7 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_LWE_FRODO() |
8 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_SIDH_IQC_REF() |
9 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_CODE_MCBITS() |
10 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_NTRU() |
11 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_MLWE_KYBER() |
12 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_PICNIC() |
13 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_BLISS() |
14 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_TESLA() |
15 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_DILITHIUM() |
16 |
DAP.Crypto.CryptoKeyType.DAP_ENC_KEY_TYPE_NULL() |
0 |
staic method DAP.Crypto.Algo.generateNewKey(keyType: int, kexBuf: bytes, keySize: int, seed: bytes) -> DAP.Crypto.Key
Generates a new key. The keyType
defines a type of the generated key. The kexBuf
should be a bytes-like object or a string. The keySize
is a key size. The seed
should be a bytes-like object or a string. The seed
is an optional argument. Returns a Key
object.
staic method DAP.Crypto.Algo.getEncSizeKey(key: DAP.Crypto.Key, size: int) -> int
Gets a size of encrypted data. The key
is a crypto key that is used for encryption. The size
is a size of a data. Returns the size of encrypted data using an algorithm, to which this key belongs.
staic method DAP.Crypto.Algo.getDecSizeKey(key: DAP.Crypto.Key, size: int) -> int
Gets a size of decrypted data. The key
is a crypto key that is used for decryption. The size
is a size of a data. Returns a size of decrypted data using an algorithm, to which this key belongs.
staic method DAP.Crypto.Algo.newKeyIAES(key: DAP.Crypto.Key) -> int
Takes a key and adds the IAES key to it. The key
is a crypto key. Returns 0
if successful.
staic method DAP.Crypto.Algo.deleteKeyIAES(key: DAP.Crypto.Key) -> int
Takes a key and removes the IAES key from it. The key
is a crypto key. Returns 0
if successful.
staic method DAP.Crypto.Algo.generateKeyIAES(key: DAP.Crypto.Key, kexBuf: bytes, kexSize: int, seed: bytes, seedSize: int) -> int
Generates a IAES key. The function accepts a key, bytes, a size of bytes, a seed and a size of a seed. Returns 0
if successful.
staic method DAP.Crypto.Algo.encodeSizeIAES256(size: int) -> int
The function accepts a size of data and returns the size of encrypted data using the algorithm.
staic method DAP.Crypto.Algo.decodeSizeIAES256(size: int) -> int
The function accepts a size of data and returns the size of decrypted data using the algorithm.
staic method DAP.Crypto.Algo.encryptIAES256CBCFast(key: DAP.Crypto.Key, in: bytes, size: int, sizeOut: int) -> str
Encrypts data using the IAES256CBCFast algorithm. The in
should be bytes-like objeсt.
staic method DAP.Crypto.Algo.decryptIAES256CBCFast(key: DAP.Crypto.Key, in: bytes, size: int, sizeOut: int) -> str
Decrypts data using the IAES256CBCFast algorithm.
staic method DAP.Crypto.Algo.newKeyOAES(key: DAP.Crypto.Key) -> int
The function takes a key and adds the IAES key to it. Returns 0
if successful.
staic method DAP.Crypto.Algo.deleteKeyOAES(key: DAP.Crypto.Key) -> int
The function takes an object of CryptoKey type to input and removes the IAES key from it. Returns 0
if successful.
staic method DAP.Crypto.Algo.generateKeyOAES(key: DAP.Crypto.Key, kexBuf: bytes, kexSize: int, seed: bytes, seedSize: int) -> int
Generates a key. The function accepts a key, bytes, a size of bytes, a seed and a size of a seed. Returns 0
if successful.
staic method DAP.Crypto.Algo.encodeSizeOAES(size: int) -> int
The function accepts a size of data and returns the size of encrypted data using the algorithm.
staic method DAP.Crypto.Algo.decodeSizeOAES(size: int) -> int
The function accepts a size of data and returns the size of decrypted data using the algorithm.
staic method DAP.Crypto.Algo.encryptOAESFast(key: DAP.Crypto.Key, in : bytes, size: int, sizeOut: int) -> str
The function encrypts data.
staic method DAP.Crypto.Algo.decryptOAESFast(key: DAP.Crypto.Key, in : bytes, size: int, sizeOut: int) -> str
The function decrypts data.
class DAP.Crypto.Cert
Class provides working with certificates.
static object DAP.Crypto.Cert.generate(certName: str, certKeyType: int, seed: str) -> DAP.Crypto.Cert
Generates a certificate. The certName
argument is name of certificate, the certKeyType
is a type of a certificate key (see newKey()
). The seed
is a seed string. Returns the DAP.Crypto.Cert
object if successful.
static object DAP.Crypto.Cert.load(certName: str) -> DAP.Crypto.Cert
Loads certificate by a name. The certName
is a name of certificate. Returns an instance of the Cert
object.
object object CellFrame.Cert.save() -> int
Saves to the first directory in cert folders list. Returns 0
if successful or an error code less than zero otherwise.
class DAP.Crypto.Sign
Class provides working with a sign.
getter DAP.Crypto.Sign.type -> DAP.Crypto.SignType
Gets a sign type.
getter DAP.Crypto.Sign.pkey -> DAP.Crypto..Pkey
Gets a public key.
getter DAP.Crypto.Sign.pkey -> DAP.Crypto.HashFast
Gets a public key.
getter DAP.Crypto.Sign.size -> int
Gets a size.
class DAP.Crypto.SignType
Class provides working with a sign type.
class DAP.Crypto.Key
Class provides working with a key.
class DAP.Crypto.Pkey
Class provides working with a sign type. It is a wrapper over the dap_pkey
plain C structure of CellFrame SDK.
getter DAP.Crypto.Pkey.hash -> DAP.Crypto.HashFast
Gets a hash.
getter DAP.Crypto.Pkey.type -> DAP.Crypto.PkeyType
Gets a sign type.
getter DAP.Crypto.Pkey.size -> int
Gets a size.
class DAP.Crypto.PkeyType
Class provides working with a public key type.
class DAP.Crypto.HashFast
Class provides working with a public key type.
static method DAP.Crypto.HashFast.fromString(hash: str) -> DAP.Crypto.HashFast
Converts the hash
string to the HashFast
object.
object method DAP.Crypto.HashFast.hashFast(bytes: bytes, dataSize: int) -> bool
Calculates SHA3_256 hash for bytes
specific data. Returns True
if successful, False
otherwise.
static method DAP.Crypto.HashFast.compare(hash1: DAP.Crypto.HashFast, hash2: CellFrame.ChainHashFast) -> bool
Compares a pair of hash1
and hash 2
. Returns True
if they are equal otherwise False
.
object method DAP.Crypto.HashFast.isBlank() -> bool
Checks if the instance is empty. Returns True
if it is blank otherwise False
.
object method DAP.Crypto.HashFast.toStr(string: str, strMax: int) -> (str, int)
Converts the instance to a string. The strMax
is a maximum string lenghts. Returns a tuple consisting of a string and a maximul string lengs.
object method DAP.Crypto.HashFast.toStrNew() -> str
Converts the instance to a string. Returns a string.
object method DAP.Crypto.HashFast.__str__() -> str
Converts the instance to a string. Returns a string.