Encryption / decryption functions using GOST
Encryption / decryption functions using GOST
How many unique symbols in password should be
How many unique symbols in password should be
How many unique bytes in secret key should be
How many unique bytes in secret key should be
(algo-name cp)
Get algorithm name for given crypto primitive. Returns String name.
Get algorithm name for given crypto primitive. Returns String name.
(byte-array->secret-key sk-bytes)
(byte-array->secret-key sk-bytes algo-name)
Create secret key from the byte array. Returns ^SecretKeySpec. This function prevents the loading of weak keys. Params:
sk-bytes
- byte array 32 bytes lengthalgo
- allowed values "GOST28147" or "GOST3412-2015" (default)Create secret key from the byte array. Returns ^SecretKeySpec. This function prevents the loading of weak keys. Params: * `sk-bytes` - byte array 32 bytes length * `algo` - allowed values "GOST28147" or "GOST3412-2015" (default)
(compress-and-encrypt-stream cipher
input
output
&
{:keys [close-streams?] :or {close-streams? true}})
Compress and then encrypt given streaming input and write encrypted data to streaming output, using given initialized ^Cipher in encryption mode. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
Compress and then encrypt given streaming input and write encrypted data to streaming output, using given initialized ^Cipher in encryption mode. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
(compress-bytes plain-bytes)
Compress plain bytes array using Deflate Zip. Returns: byte array of compressed data.
Compress plain bytes array using Deflate Zip. Returns: byte array of compressed data.
(compress-stream input
output
&
{:keys [close-streams?] :or {close-streams? true}})
Compress given streaming input and write compressed bytes to streaming output. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
Compress given streaming input and write compressed bytes to streaming output. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
(count-unique b-array)
Count unique elements in a byte array.
Count unique elements in a byte array.
(decompress-bytes compressed-bytes)
Decompress bytes using Deflate Zip. Returns: byte array of plain data.
Decompress bytes using Deflate Zip. Returns: byte array of plain data.
(decompress-stream input
output
&
{:keys [close-streams?] :or {close-streams? true}})
Decompress given streaming input and write uncompressed bytes to streaming output. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
Decompress given streaming input and write uncompressed bytes to streaming output. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
(decrypt-and-decompress-stream cipher
input
output
&
{:keys [close-streams?]
:or {close-streams? true}})
Decrypt and then decompress given streaming input and write plain data to streaming output, using given initialized ^Cipher in decryption mode. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
Decrypt and then decompress given streaming input and write plain data to streaming output, using given initialized ^Cipher in decryption mode. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
(decrypt-bytes cipher encrypted-bytes)
Decrypt data using given initialized ^Cipher in decryption mode. Returns plain data bytes array.
Decrypt data using given initialized ^Cipher in decryption mode. Returns plain data bytes array.
(decrypt-stream cipher
input
output
&
{:keys [close-streams?] :or {close-streams? true}})
Decrypt given streaming input and write plain data to streaming output, using given initialized ^Cipher in decryption mode. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
Decrypt given streaming input and write plain data to streaming output, using given initialized ^Cipher in decryption mode. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
(encrypt-bytes cipher plain-bytes)
Encrypt plain data using given initialized ^Cipher in encryption mode. Returns encrypted bytes array.
Encrypt plain data using given initialized ^Cipher in encryption mode. Returns encrypted bytes array.
(encrypt-stream cipher
input
output
&
{:keys [close-streams?] :or {close-streams? true}})
Encrypt given streaming input and write encrypted data to streaming output, using given initialized ^Cipher in encryption mode. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
Encrypt given streaming input and write encrypted data to streaming output, using given initialized ^Cipher in encryption mode. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Output should be File, URI, URL, Socket, or filename as String which will be coerced to BufferedOutputStream and auto closed after.
(generate-secret-bytes-from-password password-string)
(generate-secret-bytes-from-password password-string iter-count)
Generate secret key bytes using given password. Returns secret key bytes array length of 32 bytes.
Generate secret key bytes using given password. Returns secret key bytes array length of 32 bytes.
(generate-secret-key)
(generate-secret-key algo-name)
Generate secret key using SecureRandom. By default, it generates Secret key for GOST3412-2015. Params:
algo-name
- String, allowed values "GOST28147" or "GOST3412-2015" (default)
Returns ^SecretKeySpec keyGenerate secret key using SecureRandom. By default, it generates Secret key for GOST3412-2015. Params: * `algo-name` - String, allowed values "GOST28147" or "GOST3412-2015" (default) Returns ^SecretKeySpec key
(init-cipher-mode algo-name cipher-mode)
Init cipher mode. Returns ^Cipher. Allowed cipher modes: :cfb-mode :ctr-mode :cbc-mode
Init cipher mode. Returns ^Cipher. Allowed cipher modes: :cfb-mode :ctr-mode :cbc-mode
(init-gost-named-params algo-name iv param-name)
Init algorithm using given init vector and S-Box named parameters. Returns ^AlgorithmParameterSpec - initialized GOST algorithm parameters. Allowed param names for GOST28147-89: "E-A" - Gost28147_89_CryptoPro_A_ParamSet (most used) "E-B" - Gost28147_89_CryptoPro_B_ParamSet (most used) "E-C" - Gost28147_89_CryptoPro_C_ParamSet "E-D" - Gost28147_89_CryptoPro_D_ParamSet "Param-Z" - tc26_gost_28147_param_Z
For GOST3412-2015 - param names are ignored.
Init algorithm using given init vector and S-Box named parameters. Returns ^AlgorithmParameterSpec - initialized GOST algorithm parameters. Allowed param names for GOST28147-89: "E-A" - Gost28147_89_CryptoPro_A_ParamSet (most used) "E-B" - Gost28147_89_CryptoPro_B_ParamSet (most used) "E-C" - Gost28147_89_CryptoPro_C_ParamSet "E-D" - Gost28147_89_CryptoPro_D_ParamSet "Param-Z" - tc26_gost_28147_param_Z For GOST3412-2015 - param names are ignored.
(init-gost-oid-params algo-name iv oid-name)
Init algorithm using given init vector and S-Box OID parameters. Returns ^AlgorithmParameterSpec - initialized GOST algorithm parameters. For GOST3412-2015 - oid-name is ignored.
Init algorithm using given init vector and S-Box OID parameters. Returns ^AlgorithmParameterSpec - initialized GOST algorithm parameters. For GOST3412-2015 - oid-name is ignored.
(init-gost-sbox-binary-params algo-name iv s-box)
Init algorithm using given init vector and S-Box binary array. Returns ^AlgorithmParameterSpec - initialized GOST algorithm parameters. For GOST3412-2015 - s-box bytes are ignored.
Init algorithm using given init vector and S-Box binary array. Returns ^AlgorithmParameterSpec - initialized GOST algorithm parameters. For GOST3412-2015 - s-box bytes are ignored.
(iv-length-by-algo-mode algo-name cipher-mode)
Return IV length by algo and cipher mode
Return IV length by algo and cipher mode
(mac-28147-stream secret-key input)
(mac-28147-stream secret-key
input
s-box
&
{:keys [close-streams?] :or {close-streams? true}})
Calculate MAC for input stream using secret-key and GOST28147. Algorithm is set inside ^SecretKeySpec. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Returns byte array with calculated MAC.
Calculate MAC for input stream using secret-key and GOST28147. Algorithm is set inside ^SecretKeySpec. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Returns byte array with calculated MAC.
(mac-3412-stream secret-key
input
&
{:keys [close-streams?] :or {close-streams? true}})
Calculate MAC for input stream using secret-key and GOST3412. Algorithm is set inside ^SecretKeySpec. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Returns byte array with calculated MAC.
Calculate MAC for input stream using secret-key and GOST3412. Algorithm is set inside ^SecretKeySpec. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Returns byte array with calculated MAC.
(mac-length-by-algo algo-name)
Return Mac length by algo mode
Return Mac length by algo mode
(mac-stream secret-key input)
(mac-stream secret-key input s-box)
Calculate MAC for plain data stream using secret-key. Algorithm is set inside ^SecretKeySpec. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Returns byte array with calculated MAC.
Calculate MAC for plain data stream using secret-key. Algorithm is set inside ^SecretKeySpec. As input may be: File, URI, URL, Socket, byte array, or filename as String which will be coerced to BufferedInputStream and auto closed after. Returns byte array with calculated MAC.
(new-decryption-cipher secret-key cipher-mode algo-params)
Create new cipher for decryption. Algorithm is set inside SecretKeySpec. Appropriate IV for decryption should be set inside ^AlgorithmParameterSpec Allowed cipher modes: :cfb-mode :ctr-mode :cbc-mode Returns ^Cipher.
Create new cipher for decryption. Algorithm is set inside SecretKeySpec. Appropriate IV for decryption should be set inside ^AlgorithmParameterSpec Allowed cipher modes: :cfb-mode :ctr-mode :cbc-mode Returns ^Cipher.
(new-encryption-cipher secret-key cipher-mode)
(new-encryption-cipher secret-key cipher-mode algo-params)
Create new cipher for encryption. Algorithm is set inside SecretKeySpec. Allowed cipher modes: :cfb-mode :ctr-mode :cbc-mode Returns ^Cipher.
Create new cipher for encryption. Algorithm is set inside SecretKeySpec. Allowed cipher modes: :cfb-mode :ctr-mode :cbc-mode Returns ^Cipher.
(new-iv algo-name cipher-mode)
Create new random init vector using SecureRandom for given algorithm. Allowed cipher modes: :cfb-mode :ctr-mode :cbc-mode Returns byte array appropriate length for algorithm with random data.
Create new random init vector using SecureRandom for given algorithm. Allowed cipher modes: :cfb-mode :ctr-mode :cbc-mode Returns byte array appropriate length for algorithm with random data.
(new-iv-16)
Create new random init vector using SecureRandom. Returns byte array 16 bytes length with random data.
Create new random init vector using SecureRandom. Returns byte array 16 bytes length with random data.
(new-iv-8)
Create new random init vector using SecureRandom. Returns byte array 8 bytes length with random data.
Create new random init vector using SecureRandom. Returns byte array 8 bytes length with random data.
(protect-bytes secret-key data)
(protect-bytes secret-key data algo-spec)
Encrypt, compress, calculate MAC for plain data. IV is always random. Encryption mode is CFB. For 28147-89 default s-box is id-Gost28147-89-CryptoPro-A-ParamSet. For GOST3412-2015 s-box is ignored. Returns bytes array with structure: [IV, encrypted(Mac), encrypted(compressed-data)]
Encrypt, compress, calculate MAC for plain data. IV is always random. Encryption mode is CFB. For 28147-89 default s-box is id-Gost28147-89-CryptoPro-A-ParamSet. For GOST3412-2015 s-box is ignored. Returns bytes array with structure: [IV, encrypted(Mac), encrypted(compressed-data)]
(protect-file secret-key input-filename output-filename)
(protect-file secret-key input-filename output-filename algo-spec)
Encrypt, compress, calculate MAC for plain data from input-filename
.
IV is always random. Encryption mode is CFB.
For 28147-89 default s-box is id-Gost28147-89-CryptoPro-A-ParamSet. For GOST3412-2015 s-box is ignored.
Save encrypted data to output-filename
(create or overwrite it) with structure: [IV, encrypted(Mac), encrypted(compressed-data)].
Returns ^String value of output-filename
if success or throw Exception if error.
Encrypt, compress, calculate MAC for plain data from `input-filename`. IV is always random. Encryption mode is CFB. For 28147-89 default s-box is id-Gost28147-89-CryptoPro-A-ParamSet. For GOST3412-2015 s-box is ignored. Save encrypted data to `output-filename` (create or overwrite it) with structure: [IV, encrypted(Mac), encrypted(compressed-data)]. Returns ^String value of `output-filename` if success or throw Exception if error.
(secret-key->byte-array k)
Convert ^SecretKeySpec to a byte array
Convert ^SecretKeySpec to a byte array
(unprotect-bytes secret-key
input
&
{:keys [s-box] :or {s-box (byte-array s-box-crypto-pro-a)}})
Decrypt, decompress input data bytes, verify MAC for decrypted plain data. For 28147-89 default s-box is id-Gost28147-89-CryptoPro-A-ParamSet. For GOST3412-2015 s-box is ignored. Returns plain data as bytes array if success or throws Exception if failure.
Decrypt, decompress input data bytes, verify MAC for decrypted plain data. For 28147-89 default s-box is id-Gost28147-89-CryptoPro-A-ParamSet. For GOST3412-2015 s-box is ignored. Returns plain data as bytes array if success or throws Exception if failure.
(unprotect-file secret-key
input-filename
output-filename
&
{:keys [s-box] :or {s-box (byte-array s-box-crypto-pro-a)}})
Decrypt, decompress content of input-filename
, verify MAC for plain data.
Save plain data to output-filename
file (create or overwrite it).
For 28147-89 default s-box is id-Gost28147-89-CryptoPro-A-ParamSet. For GOST3412-2015 s-box is ignored.
Returns ^String value of output-filename
if success or throw Exception if error.
Decrypt, decompress content of `input-filename`, verify MAC for plain data. Save plain data to `output-filename` file (create or overwrite it). For 28147-89 default s-box is id-Gost28147-89-CryptoPro-A-ParamSet. For GOST3412-2015 s-box is ignored. Returns ^String value of `output-filename` if success or throw Exception if error.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close