Search in sources :

Example 1 with CipherParameters

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

the class CryptoManagerImpl method obfuscate.

@Override
public byte[] obfuscate(byte[] data) {
    RC4Engine engine = new RC4Engine();
    CipherParameters params = new KeyParameter(new SHA1Simple().calculateHash(getOBSID()));
    engine.init(true, params);
    byte[] temp = new byte[1024];
    engine.processBytes(temp, 0, 1024, temp, 0);
    final byte[] obs_value = new byte[data.length];
    engine.processBytes(data, 0, data.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)

Example 2 with CipherParameters

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

the class JDKDSASigner method engineInitVerify.

@Override
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    CipherParameters param = null;
    if (publicKey instanceof ECKey) {
        param = ECUtil.generatePublicKeyParameter(publicKey);
    } else if (publicKey instanceof DSAKey) {
        param = DSAUtil.generatePublicKeyParameter(publicKey);
    } else {
        try {
            /*
                byte[]  bytes = publicKey.getEncoded();

                publicKey = JDKKeyFactory.createPublicKeyFromDERStream(
                                        new ByteArrayInputStream(bytes));

                if (publicKey instanceof ECKey)
                {
                    param = ECUtil.generatePublicKeyParameter(publicKey);
                }
                else if (publicKey instanceof DSAKey)
                {
                    param = DSAUtil.generatePublicKeyParameter(publicKey);
                }
                else
                {
                */
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        // }
        } catch (Exception e) {
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        }
    }
    digest.reset();
    signer.init(false, param);
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) DSAKey(java.security.interfaces.DSAKey) ECKey(org.gudy.bouncycastle.jce.interfaces.ECKey) IOException(java.io.IOException)

Example 3 with CipherParameters

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

the class UDPConnectionSet method getCipher.

private RC4Engine getCipher(byte[] key) {
    SecretKeySpec secret_key_spec = new SecretKeySpec(key, "RC4");
    RC4Engine rc4_engine = new RC4Engine();
    CipherParameters params_a = new KeyParameter(secret_key_spec.getEncoded());
    // for RC4 enc/dec is irrelevant
    rc4_engine.init(true, params_a);
    // skip first 1024 bytes of stream to protected against a Fluhrer, Mantin and Shamir attack
    byte[] temp = new byte[1024];
    rc4_engine.processBytes(temp, 0, temp.length, temp, 0);
    return (rc4_engine);
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) SecretKeySpec(javax.crypto.spec.SecretKeySpec) KeyParameter(org.gudy.bouncycastle.crypto.params.KeyParameter) RC4Engine(org.gudy.bouncycastle.crypto.engines.RC4Engine)

Example 4 with CipherParameters

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

the class JCEECDHKeyAgreement method engineDoPhase.

@Override
protected Key engineDoPhase(Key key, boolean lastPhase) throws InvalidKeyException, IllegalStateException {
    if (privKey == null) {
        throw new IllegalStateException("EC Diffie-Hellman not initialised.");
    }
    if (!lastPhase) {
        throw new IllegalStateException("EC Diffie-Hellman can only be between two parties.");
    }
    if (!(key instanceof ECPublicKey)) {
        throw new InvalidKeyException("EC Key Agreement doPhase requires ECPublicKey");
    }
    CipherParameters pubKey = ECUtil.generatePublicKeyParameter((PublicKey) key);
    result = agreement.calculateAgreement(pubKey);
    return null;
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) ECPublicKey(org.gudy.bouncycastle.jce.interfaces.ECPublicKey)

Example 5 with CipherParameters

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

the class JDKDigestSignature method engineInitVerify.

@Override
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
    if (!(publicKey instanceof RSAPublicKey)) {
        throw new InvalidKeyException("Supplied key is not a RSAPublicKey instance");
    }
    CipherParameters param = RSAUtil.generatePublicKeyParameter((RSAPublicKey) publicKey);
    digest.reset();
    cipher.init(false, param);
}
Also used : CipherParameters(org.gudy.bouncycastle.crypto.CipherParameters) RSAPublicKey(java.security.interfaces.RSAPublicKey)

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