Search in sources :

Example 6 with CipherParameters

use of org.gudy.bouncycastle.crypto.CipherParameters in project BiglyBT by BiglySoftware.

the class JDKDigestSignature method engineInitSign.

@Override
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
    if (!(privateKey instanceof RSAPrivateKey)) {
        throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
    }
    CipherParameters param = RSAUtil.generatePrivateKeyParameter((RSAPrivateKey) privateKey);
    digest.reset();
    cipher.init(true, param);
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) RSAPrivateKey(java.security.interfaces.RSAPrivateKey)

Example 7 with CipherParameters

use of org.gudy.bouncycastle.crypto.CipherParameters in project BiglyBT by BiglySoftware.

the class JDKDSASigner method engineInitSign.

@Override
protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
    CipherParameters param = null;
    if (privateKey instanceof ECKey) {
        param = ECUtil.generatePrivateKeyParameter(privateKey);
    } else {
        param = DSAUtil.generatePrivateKeyParameter(privateKey);
    }
    digest.reset();
    if (random != null) {
        signer.init(true, new ParametersWithRandom(param, random));
    } else {
        signer.init(true, param);
    }
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) ParametersWithRandom(org.gudy.bouncycastle.crypto.params.ParametersWithRandom) ECKey(org.gudy.bouncycastle.jce.interfaces.ECKey)

Example 8 with CipherParameters

use of org.gudy.bouncycastle.crypto.CipherParameters in project BiglyBT by BiglySoftware.

the class JCEIESCipher method engineInit.

public void engineInit(int opmode, Key key, AlgorithmParameterSpec params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (!(key instanceof IESKey)) {
        throw new InvalidKeyException("must be passed IE key");
    }
    if (params == null && (opmode == Cipher.ENCRYPT_MODE || opmode == Cipher.WRAP_MODE)) {
        // 
        // if nothing is specified we set up for a 128 bit mac, with
        // 128 bit derivation vectors.
        // 
        byte[] d = new byte[16];
        byte[] e = new byte[16];
        if (random == null) {
            random = new SecureRandom();
        }
        random.nextBytes(d);
        random.nextBytes(e);
        params = new IESParameterSpec(d, e, 128);
    } else if (!(params instanceof IESParameterSpec)) {
        throw new InvalidAlgorithmParameterException("must be passed IES parameters");
    }
    IESKey ieKey = (IESKey) key;
    CipherParameters pubKey;
    CipherParameters privKey;
    if (ieKey.getPublic() instanceof JCEECPublicKey) {
        pubKey = ECUtil.generatePublicKeyParameter(ieKey.getPublic());
        privKey = ECUtil.generatePrivateKeyParameter(ieKey.getPrivate());
    } else {
        pubKey = DHUtil.generatePublicKeyParameter(ieKey.getPublic());
        privKey = DHUtil.generatePrivateKeyParameter(ieKey.getPrivate());
    }
    this.engineParams = (IESParameterSpec) params;
    IESParameters p = new IESParameters(engineParams.getDerivationV(), engineParams.getEncodingV(), engineParams.getMacKeySize());
    this.state = opmode;
    buffer.reset();
    switch(opmode) {
        case Cipher.ENCRYPT_MODE:
        case Cipher.WRAP_MODE:
            cipher.init(true, privKey, pubKey, p);
            break;
        case Cipher.DECRYPT_MODE:
        case Cipher.UNWRAP_MODE:
            cipher.init(false, privKey, pubKey, p);
            break;
        default:
            System.out.println("eeek!");
    }
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) IESParameterSpec(org.gudy.bouncycastle.jce.spec.IESParameterSpec) IESKey(org.gudy.bouncycastle.jce.interfaces.IESKey) IESParameters(org.gudy.bouncycastle.crypto.params.IESParameters)

Example 9 with CipherParameters

use of org.gudy.bouncycastle.crypto.CipherParameters in project BiglyBT by BiglySoftware.

the class DHTControlImpl method getObfuscatedValue.

protected byte[] getObfuscatedValue(byte[] plain_key) {
    RC4Engine engine = new RC4Engine();
    CipherParameters params = new KeyParameter(new SHA1Simple().calculateHash(plain_key));
    engine.init(true, params);
    byte[] temp = new byte[1024];
    engine.processBytes(temp, 0, 1024, temp, 0);
    final byte[] obs_value = new byte[plain_key.length];
    engine.processBytes(plain_key, 0, plain_key.length, obs_value, 0);
    return (obs_value);
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) KeyParameter(org.gudy.bouncycastle.crypto.params.KeyParameter) RC4Engine(org.gudy.bouncycastle.crypto.engines.RC4Engine)

Aggregations

CipherParameters (org.gudy.bouncycastle.crypto.CipherParameters)9 RC4Engine (org.gudy.bouncycastle.crypto.engines.RC4Engine)3 KeyParameter (org.gudy.bouncycastle.crypto.params.KeyParameter)3 ECKey (org.gudy.bouncycastle.jce.interfaces.ECKey)2 IOException (java.io.IOException)1 DSAKey (java.security.interfaces.DSAKey)1 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 IESParameters (org.gudy.bouncycastle.crypto.params.IESParameters)1 ParametersWithRandom (org.gudy.bouncycastle.crypto.params.ParametersWithRandom)1 ECPublicKey (org.gudy.bouncycastle.jce.interfaces.ECPublicKey)1 IESKey (org.gudy.bouncycastle.jce.interfaces.IESKey)1 IESParameterSpec (org.gudy.bouncycastle.jce.spec.IESParameterSpec)1