com.github.isaichkindanila.crypt.lib.cipher.StandardStreamCipher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crypt-lib Show documentation
Show all versions of crypt-lib Show documentation
Simple Java library for stream ciphers based encryption
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;
}
}