Search in sources :

Example 1 with StreamCipher

use of org.spongycastle.crypto.StreamCipher in project KeePassDX by Kunzisoft.

the class PwStreamCipherFactory method getSalsa20.

private static StreamCipher getSalsa20(byte[] key) {
    // Build stream cipher key
    byte[] key32 = CryptoUtil.hashSha256(key);
    KeyParameter keyParam = new KeyParameter(key32);
    ParametersWithIV ivParam = new ParametersWithIV(keyParam, SALSA_IV);
    StreamCipher cipher = new Salsa20Engine();
    cipher.init(true, ivParam);
    return cipher;
}
Also used : ParametersWithIV(org.spongycastle.crypto.params.ParametersWithIV) KeyParameter(org.spongycastle.crypto.params.KeyParameter) Salsa20Engine(org.spongycastle.crypto.engines.Salsa20Engine) StreamCipher(org.spongycastle.crypto.StreamCipher)

Example 2 with StreamCipher

use of org.spongycastle.crypto.StreamCipher in project KeePassDX by Kunzisoft.

the class PwStreamCipherFactory method getChaCha20.

private static StreamCipher getChaCha20(byte[] key) {
    // Build stream cipher key
    byte[] hash = CryptoUtil.hashSha512(key);
    byte[] key32 = new byte[32];
    byte[] iv = new byte[12];
    System.arraycopy(hash, 0, key32, 0, 32);
    System.arraycopy(hash, 32, iv, 0, 12);
    KeyParameter keyParam = new KeyParameter(key32);
    ParametersWithIV ivParam = new ParametersWithIV(keyParam, iv);
    StreamCipher cipher = new ChaCha7539Engine();
    cipher.init(true, ivParam);
    return cipher;
}
Also used : ParametersWithIV(org.spongycastle.crypto.params.ParametersWithIV) ChaCha7539Engine(org.spongycastle.crypto.engines.ChaCha7539Engine) KeyParameter(org.spongycastle.crypto.params.KeyParameter) StreamCipher(org.spongycastle.crypto.StreamCipher)

Aggregations

StreamCipher (org.spongycastle.crypto.StreamCipher)2 KeyParameter (org.spongycastle.crypto.params.KeyParameter)2 ParametersWithIV (org.spongycastle.crypto.params.ParametersWithIV)2 ChaCha7539Engine (org.spongycastle.crypto.engines.ChaCha7539Engine)1 Salsa20Engine (org.spongycastle.crypto.engines.Salsa20Engine)1