1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
|
# oscrypto.symmetric API Documentation
The *oscrypto.symmetric* submodule implements symmetric/secret key encryption
and decryption. The following functions comprise the public API:
- AES
- [`aes_cbc_pkcs7_encrypt()`](#aes_cbc_pkcs7_encrypt-function)
- [`aes_cbc_pkcs7_decrypt()`](#aes_cbc_pkcs7_decrypt-function)
- [`aes_cbc_no_padding_encrypt()`](#aes_cbc_no_padding_encrypt-function)
- [`aes_cbc_no_padding_decrypt()`](#aes_cbc_no_padding_decrypt-function)
- Triple DES
- [`tripledes_cbc_pkcs5_encrypt()`](#tripledes_cbc_pkcs5_encrypt-function)
- [`tripledes_cbc_pkcs5_decrypt()`](#tripledes_cbc_pkcs5_decrypt-function)
- DES
- [`des_cbc_pkcs5_encrypt()`](#des_cbc_pkcs5_encrypt-function)
- [`des_cbc_pkcs5_decrypt()`](#des_cbc_pkcs5_decrypt-function)
- RC4
- [`rc4_encrypt()`](#rc4_encrypt-function)
- [`rc4_decrypt()`](#rc4_decrypt-function)
- RC2
- [`rc2_cbc_pkcs5_encrypt()`](#rc2_cbc_pkcs5_encrypt-function)
- [`rc2_cbc_pkcs5_decrypt()`](#rc2_cbc_pkcs5_decrypt-function)
### `aes_cbc_pkcs7_encrypt()` function
> ```python
> def aes_cbc_pkcs7_encrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string either 16, 24 or 32 bytes long
>
> :param data:
> The plaintext - a byte string
>
> :param iv:
> The initialization vector - either a byte string 16-bytes long or None
> to generate an IV
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A tuple of two byte strings (iv, ciphertext)
> """
> ```
>
> Encrypts plaintext using AES in CBC mode with a 128, 192 or 256 bit key and
> PKCS#7 padding.
### `aes_cbc_pkcs7_decrypt()` function
> ```python
> def aes_cbc_pkcs7_decrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string either 16, 24 or 32 bytes long
>
> :param data:
> The ciphertext - a byte string
>
> :param iv:
> The initialization vector - a byte string 16-bytes long
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A byte string of the plaintext
> """
> ```
>
> Decrypts AES ciphertext in CBC mode using a 128, 192 or 256 bit key
### `aes_cbc_no_padding_encrypt()` function
> ```python
> def aes_cbc_no_padding_encrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string either 16, 24 or 32 bytes long
>
> :param data:
> The plaintext - a byte string
>
> :param iv:
> The initialization vector - either a byte string 16-bytes long or None
> to generate an IV
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A tuple of two byte strings (iv, ciphertext)
> """
> ```
>
> Encrypts plaintext using AES in CBC mode with a 128, 192 or 256 bit key and
> no padding. This means the ciphertext must be an exact multiple of 16 bytes
> long.
### `aes_cbc_no_padding_decrypt()` function
> ```python
> def aes_cbc_no_padding_decrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string either 16, 24 or 32 bytes long
>
> :param data:
> The ciphertext - a byte string
>
> :param iv:
> The initialization vector - a byte string 16-bytes long
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A byte string of the plaintext
> """
> ```
>
> Decrypts AES ciphertext in CBC mode using a 128, 192 or 256 bit key and no
> padding.
### `tripledes_cbc_pkcs5_encrypt()` function
> ```python
> def tripledes_cbc_pkcs5_encrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string 16 or 24 bytes long (2 or 3 key mode)
>
> :param data:
> The plaintext - a byte string
>
> :param iv:
> The initialization vector - a byte string 8-bytes long or None
> to generate an IV
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A tuple of two byte strings (iv, ciphertext)
> """
> ```
>
> Encrypts plaintext using 3DES in CBC mode using either the 2 or 3 key
> variant (16 or 24 byte long key) and PKCS#5 padding.
### `tripledes_cbc_pkcs5_decrypt()` function
> ```python
> def tripledes_cbc_pkcs5_decrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string 16 or 24 bytes long (2 or 3 key mode)
>
> :param data:
> The ciphertext - a byte string
>
> :param iv:
> The initialization vector - a byte string 8-bytes long
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A byte string of the plaintext
> """
> ```
>
> Decrypts 3DES ciphertext in CBC mode using either the 2 or 3 key variant
> (16 or 24 byte long key) and PKCS#5 padding.
### `des_cbc_pkcs5_encrypt()` function
> ```python
> def des_cbc_pkcs5_encrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string 8 bytes long (includes error correction bits)
>
> :param data:
> The plaintext - a byte string
>
> :param iv:
> The initialization vector - a byte string 8-bytes long or None
> to generate an IV
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A tuple of two byte strings (iv, ciphertext)
> """
> ```
>
> Encrypts plaintext using DES in CBC mode with a 56 bit key and PKCS#5
> padding.
### `des_cbc_pkcs5_decrypt()` function
> ```python
> def des_cbc_pkcs5_decrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string 8 bytes long (includes error correction bits)
>
> :param data:
> The ciphertext - a byte string
>
> :param iv:
> The initialization vector - a byte string 8-bytes long
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A byte string of the plaintext
> """
> ```
>
> Decrypts DES ciphertext in CBC mode using a 56 bit key and PKCS#5 padding.
### `rc4_encrypt()` function
> ```python
> def rc4_encrypt(key, data):
> """
> :param key:
> The encryption key - a byte string 5-16 bytes long
>
> :param data:
> The plaintext - a byte string
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A byte string of the ciphertext
> """
> ```
>
> Encrypts plaintext using RC4 with a 40-128 bit key
### `rc4_decrypt()` function
> ```python
> def rc4_decrypt(key, data):
> """
> :param key:
> The encryption key - a byte string 5-16 bytes long
>
> :param data:
> The ciphertext - a byte string
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A byte string of the plaintext
> """
> ```
>
> Decrypts RC4 ciphertext using a 40-128 bit key
### `rc2_cbc_pkcs5_encrypt()` function
> ```python
> def rc2_cbc_pkcs5_encrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string 8 bytes long
>
> :param data:
> The plaintext - a byte string
>
> :param iv:
> The initialization vector - a byte string 8-bytes long or None
> to generate an IV
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A tuple of two byte strings (iv, ciphertext)
> """
> ```
>
> Encrypts plaintext using RC2 in CBC mode with a 40-128 bit key and PKCS#5
> padding.
### `rc2_cbc_pkcs5_decrypt()` function
> ```python
> def rc2_cbc_pkcs5_decrypt(key, data, iv):
> """
> :param key:
> The encryption key - a byte string 8 bytes long
>
> :param data:
> The ciphertext - a byte string
>
> :param iv:
> The initialization vector - a byte string 8 bytes long
>
> :raises:
> ValueError - when any of the parameters contain an invalid value
> TypeError - when any of the parameters are of the wrong type
> OSError - when an error is returned by the OS crypto library
>
> :return:
> A byte string of the plaintext
> """
> ```
>
> Decrypts RC2 ciphertext ib CBC mode using a 40-128 bit key and PKCS#5
> padding.
|