Search in sources :

Example 1 with ParametersWithRandom

use of com.github.zhenwei.core.crypto.params.ParametersWithRandom in project LinLong-Java by zhenwei1108.

the class CramerShoupCoreEngine method init.

/**
 * initialise the CramerShoup engine.
 *
 * @param forEncryption whether this engine should encrypt or decrypt
 * @param param         the necessary CramerShoup key parameters.
 */
public void init(boolean forEncryption, CipherParameters param) {
    SecureRandom providedRandom = null;
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        key = (CramerShoupKeyParameters) rParam.getParameters();
        providedRandom = rParam.getRandom();
    } else {
        key = (CramerShoupKeyParameters) param;
    }
    this.random = initSecureRandom(forEncryption, providedRandom);
    this.forEncryption = forEncryption;
}
Also used : SecureRandom(java.security.SecureRandom) ParametersWithRandom(com.github.zhenwei.core.crypto.params.ParametersWithRandom)

Example 2 with ParametersWithRandom

use of com.github.zhenwei.core.crypto.params.ParametersWithRandom in project LinLong-Java by zhenwei1108.

the class GOST28147WrapEngine method init.

public void init(boolean forWrapping, CipherParameters param) {
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom pr = (ParametersWithRandom) param;
        param = pr.getParameters();
    }
    ParametersWithUKM pU = (ParametersWithUKM) param;
    cipher.init(forWrapping, pU.getParameters());
    mac.init(new ParametersWithIV(pU.getParameters(), pU.getUKM()));
}
Also used : ParametersWithIV(com.github.zhenwei.core.crypto.params.ParametersWithIV) ParametersWithUKM(com.github.zhenwei.core.crypto.params.ParametersWithUKM) ParametersWithRandom(com.github.zhenwei.core.crypto.params.ParametersWithRandom)

Example 3 with ParametersWithRandom

use of com.github.zhenwei.core.crypto.params.ParametersWithRandom in project LinLong-Java by zhenwei1108.

the class ECNewRandomnessTransform method init.

/**
 * initialise the underlying EC ElGamal engine.
 *
 * @param param the necessary EC key parameters.
 */
public void init(CipherParameters param) {
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom p = (ParametersWithRandom) param;
        if (!(p.getParameters() instanceof ECPublicKeyParameters)) {
            throw new IllegalArgumentException("ECPublicKeyParameters are required for new randomness transform.");
        }
        this.key = (ECPublicKeyParameters) p.getParameters();
        this.random = p.getRandom();
    } else {
        if (!(param instanceof ECPublicKeyParameters)) {
            throw new IllegalArgumentException("ECPublicKeyParameters are required for new randomness transform.");
        }
        this.key = (ECPublicKeyParameters) param;
        this.random = CryptoServicesRegistrar.getSecureRandom();
    }
}
Also used : ParametersWithRandom(com.github.zhenwei.core.crypto.params.ParametersWithRandom) ECPublicKeyParameters(com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)

Example 4 with ParametersWithRandom

use of com.github.zhenwei.core.crypto.params.ParametersWithRandom in project LinLong-Java by zhenwei1108.

the class ISO9796d1Encoding method init.

public void init(boolean forEncryption, CipherParameters param) {
    RSAKeyParameters kParam = null;
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        kParam = (RSAKeyParameters) rParam.getParameters();
    } else {
        kParam = (RSAKeyParameters) param;
    }
    engine.init(forEncryption, param);
    modulus = kParam.getModulus();
    bitSize = modulus.bitLength();
    this.forEncryption = forEncryption;
}
Also used : ParametersWithRandom(com.github.zhenwei.core.crypto.params.ParametersWithRandom) RSAKeyParameters(com.github.zhenwei.core.crypto.params.RSAKeyParameters)

Example 5 with ParametersWithRandom

use of com.github.zhenwei.core.crypto.params.ParametersWithRandom in project LinLong-Java by zhenwei1108.

the class PKCS1Encoding method init.

public void init(boolean forEncryption, CipherParameters param) {
    AsymmetricKeyParameter kParam;
    if (param instanceof ParametersWithRandom) {
        ParametersWithRandom rParam = (ParametersWithRandom) param;
        this.random = rParam.getRandom();
        kParam = (AsymmetricKeyParameter) rParam.getParameters();
    } else {
        kParam = (AsymmetricKeyParameter) param;
        if (!kParam.isPrivate() && forEncryption) {
            this.random = CryptoServicesRegistrar.getSecureRandom();
        }
    }
    engine.init(forEncryption, param);
    this.forPrivateKey = kParam.isPrivate();
    this.forEncryption = forEncryption;
    this.blockBuffer = new byte[engine.getOutputBlockSize()];
    if (pLen > 0 && fallback == null && random == null) {
        throw new IllegalArgumentException("encoder requires random");
    }
}
Also used : AsymmetricKeyParameter(com.github.zhenwei.core.crypto.params.AsymmetricKeyParameter) ParametersWithRandom(com.github.zhenwei.core.crypto.params.ParametersWithRandom)

Aggregations

ParametersWithRandom (com.github.zhenwei.core.crypto.params.ParametersWithRandom)64 CipherParameters (com.github.zhenwei.core.crypto.CipherParameters)20 InvalidKeyException (java.security.InvalidKeyException)10 AsymmetricKeyParameter (com.github.zhenwei.core.crypto.params.AsymmetricKeyParameter)7 ParametersWithIV (com.github.zhenwei.core.crypto.params.ParametersWithIV)6 ECKey (com.github.zhenwei.provider.jce.interfaces.ECKey)5 PublicKey (java.security.PublicKey)5 SecureRandom (java.security.SecureRandom)5 KeyParameter (com.github.zhenwei.core.crypto.params.KeyParameter)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)4 InvalidParameterException (java.security.InvalidParameterException)4 InvalidCipherTextException (com.github.zhenwei.core.crypto.InvalidCipherTextException)3 ECPublicKeyParameters (com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)3 ParametersWithSBox (com.github.zhenwei.core.crypto.params.ParametersWithSBox)3 ParametersWithUKM (com.github.zhenwei.core.crypto.params.ParametersWithUKM)3 Digest (com.github.zhenwei.core.crypto.Digest)2 OAEPEncoding (com.github.zhenwei.core.crypto.encodings.OAEPEncoding)2 CBCBlockCipher (com.github.zhenwei.core.crypto.modes.CBCBlockCipher)2 DHPrivateKeyParameters (com.github.zhenwei.core.crypto.params.DHPrivateKeyParameters)2 ECKeyParameters (com.github.zhenwei.core.crypto.params.ECKeyParameters)2