All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.isaichkindanila.crypt.lib.cipher.StandardStreamCipher Maven / Gradle / Ivy

The newest version!
package com.github.isaichkindanila.crypt.lib.cipher;

import java.util.function.Supplier;

/**
 * Contains all predefined stream ciphers.
 */
public enum StandardStreamCipher {
    /**
     * Fast and secure general-purpose stream cipher.
     */
    ChaCha20(() -> new ChaCha(20)),

    /**
     * Faster and less secure than ChaCha20.
     */
    ChaCha12(() -> new ChaCha(12)),

    /**
     * The fastest and the least secure among ChaCha family.
     */
    ChaCha8(() -> new ChaCha(8));


    private final Supplier constructor;

    StandardStreamCipher(Supplier constructor) {
        this.constructor = constructor;
    }

    /**
     * Creates new instance of stream cipher, initialized with passed key and IV.
     *
     * @param key cipher's key
     * @param iv  cipher's initialization vector
     * @return new initialized instance of stream cipher
     */
    public StreamCipher newInstance(byte[] key, byte[] iv) {
        StreamCipher cipher = constructor.get();
        cipher.init(key, iv);

        return cipher;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy