Example usage for org.bouncycastle.crypto.engines RC4Engine RC4Engine

List of usage examples for org.bouncycastle.crypto.engines RC4Engine RC4Engine

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.engines RC4Engine RC4Engine.

Prototype

RC4Engine

Source Link

Usage

From source file:com.aelitis.azureus.core.dht.control.impl.DHTControlImpl.java

License:Open Source License

protected byte[] getObfuscatedValue(byte[] plain_key) {
    RC4Engine engine = new RC4Engine();

    CipherParameters params = new KeyParameter(new SHA1Simple().calculateHash(plain_key));

    engine.init(true, params);/*from  w ww  .  ja v a2 s . co  m*/

    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);
}

From source file:com.aelitis.azureus.core.security.impl.CryptoManagerImpl.java

License:Open Source License

public byte[] obfuscate(byte[] data) {
    RC4Engine engine = new RC4Engine();

    CipherParameters params = new KeyParameter(new SHA1Simple().calculateHash(getOBSID()));

    engine.init(true, params);/*  ww w  .  j  a  v  a2  s . co  m*/

    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);
}

From source file:com.jrdp.core.encryption.RC4.java

License:Apache License

public synchronized void updateKey(byte[] newKey) {
    engine = new RC4Engine();
    engine.init(true, new KeyParameter(newKey));
    uses = 0;/*w  w w .j  ava 2  s. c  o  m*/
}

From source file:com.jrdp.core.encryption.RC4Session.java

License:Apache License

private byte[] updateRc4Key(byte[] originalKey, byte[] currentKey) {
    int keySize = 0;
    switch (encryptionMethod) {
    case Constants.ENCRYPTION_128BIT:
        keySize = 16;/*  www .  j  a  va  2  s  .c o m*/
        break;
    case Constants.ENCRYPTION_40BIT:
    case Constants.ENCRYPTION_56BIT:
        keySize = 8;
        break;
    case Constants.ENCRYPTION_NONE:
    case Constants.ENCRYPTION_FIPS:
        //Should never happen...
        return null;
    }

    SHA1Digest sha1 = new SHA1Digest();
    sha1.update(originalKey, 0, keySize);
    sha1.update(Constants.pad36, 0, Constants.pad36.length);
    sha1.update(currentKey, 0, currentKey.length);
    byte[] shaComponent = new byte[Rdp.SHA1_DIGEST_LENGTH];
    sha1.doFinal(shaComponent, 0);

    //StringManip.print(shaComponent, "SHA1:");

    MD5Digest md5 = new MD5Digest();
    md5.update(originalKey, 0, keySize);
    md5.update(Constants.pad5c, 0, Constants.pad5c.length);
    md5.update(shaComponent, 0, shaComponent.length);
    byte[] tempKey = new byte[Rdp.MD5_DIGEST_LENGTH];
    md5.doFinal(tempKey, 0);

    //StringManip.print(tempKey, "MD5:");

    RC4Engine rc4 = new RC4Engine();
    if (keySize == 16) {
        byte[] newKey = new byte[tempKey.length];
        rc4.init(true, new KeyParameter(tempKey));
        rc4.processBytes(tempKey, 0, tempKey.length, newKey, 0);
        return newKey;
    } else {
        byte[] newKey = new byte[8];
        byte[] smallerTmpKey = new byte[8];
        System.arraycopy(tempKey, 0, smallerTmpKey, 0, 8);
        rc4.init(true, new KeyParameter(smallerTmpKey));
        rc4.processBytes(smallerTmpKey, 0, 8, newKey, 0);
        newKey[0] = (byte) 0xd1;
        if (encryptionMethod == Constants.ENCRYPTION_40BIT) {
            newKey[1] = 0x26;
            newKey[2] = (byte) 0x9e;
        }
        return newKey;
    }
}

From source file:com.spooky.mse.u.TransportCipher.java

License:Open Source License

public TransportCipher(int mode, SecretKeySpec key_spec) {

    rc4_engine = new RC4Engine();

    CipherParameters params = new KeyParameter(key_spec.getEncoded());

    rc4_engine.init(mode == Cipher.ENCRYPT_MODE, params);

    byte[] temp = new byte[1024];

    temp = update(temp);/* w w w  .  j a  va2  s  . co m*/

}

From source file:edu.biu.scapi.primitives.prg.bc.BcRC4.java

License:Open Source License

/**
 * Passes the RC4Engine of BC to the abstract super class
 */
public BcRC4() {
    super(new RC4Engine());
}

From source file:edu.biu.scapi.primitives.prg.bc.BcRC4.java

License:Open Source License

public BcRC4(SecureRandom random) {
    super(new RC4Engine(), random);
}

From source file:edu.biu.scapi.primitives.prg.bc.BcRC4.java

License:Open Source License

public BcRC4(String randNumGenAlg) throws NoSuchAlgorithmException {

    super(new RC4Engine(), SecureRandom.getInstance(randNumGenAlg));
}

From source file:net.propero.rdp.Licence.java

License:Open Source License

/**
 * Process a demand for a licence. Find a license and transmit to server, or
 * request new licence/*  w w w.j  ava 2 s  .c om*/
 *
 * @param data
 *            Packet containing details of licence demand
 * @throws UnsupportedEncodingException
 * @throws RdesktopException
 * @throws IOException
 */
public void process_demand(RdpPacket data) throws UnsupportedEncodingException, RdesktopException, IOException {
    byte[] null_data = new byte[Secure.SEC_MODULUS_SIZE];
    byte[] server_random = new byte[Secure.SEC_RANDOM_SIZE];
    byte[] host = options.hostname.getBytes("US-ASCII");
    byte[] user = options.username.getBytes("US-ASCII");

    /* retrieve the server random */
    data.copyToByteArray(server_random, 0, data.getPosition(), server_random.length);
    data.incrementPosition(server_random.length);

    /* Null client keys are currently used */
    this.generate_keys(null_data, server_random, null_data);

    if (!options.built_in_licence && options.load_licence) {
        byte[] licence_data = load_licence();
        if ((licence_data != null) && (licence_data.length > 0)) {
            LOGGER.debug("licence_data.length = " + licence_data.length);
            /* Generate a signature for the HWID buffer */
            byte[] hwid = generate_hwid();
            byte[] signature = secure.sign(this.licence_sign_key, 16, 16, hwid, hwid.length);

            /* now crypt the hwid */
            RC4Engine rc4_licence = new RC4Engine();
            byte[] crypt_key = new byte[this.licence_key.length];
            byte[] crypt_hwid = new byte[LICENCE_HWID_SIZE];
            System.arraycopy(this.licence_key, 0, crypt_key, 0, this.licence_key.length);
            rc4_licence.init(true, new KeyParameter(crypt_key));
            rc4_licence.processBytes(hwid, 0, LICENCE_HWID_SIZE, crypt_hwid, 0);

            present(null_data, null_data, licence_data, licence_data.length, crypt_hwid, signature);
            LOGGER.debug("Presented stored licence to server!");
            return;
        }
    }
    this.send_request(null_data, null_data, user, host);
}

From source file:net.propero.rdp.Licence.java

License:Open Source License

/**
 * Process an authorisation request/*from ww  w . j  a va 2s  .c  o m*/
 *
 * @param data
 *            Packet containing request details
 * @throws RdesktopException
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
public void process_authreq(RdpPacket data)
        throws RdesktopException, UnsupportedEncodingException, IOException {

    byte[] out_token = new byte[LICENCE_TOKEN_SIZE];
    byte[] decrypt_token = new byte[LICENCE_TOKEN_SIZE];

    byte[] crypt_hwid = new byte[LICENCE_HWID_SIZE];
    byte[] sealed_buffer = new byte[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];
    byte[] out_sig = new byte[LICENCE_SIGNATURE_SIZE];
    RC4Engine rc4_licence = new RC4Engine();
    byte[] crypt_key = null;

    /* parse incoming packet and save encrypted token */
    if (parse_authreq(data) != true) {
        throw new RdesktopException("Authentication Request was corrupt!");
    }
    System.arraycopy(this.in_token, 0, out_token, 0, LICENCE_TOKEN_SIZE);

    /* decrypt token. It should read TEST in Unicode */
    crypt_key = new byte[this.licence_key.length];
    System.arraycopy(this.licence_key, 0, crypt_key, 0, this.licence_key.length);
    rc4_licence.init(false, new KeyParameter(crypt_key));
    rc4_licence.processBytes(this.in_token, 0, LICENCE_TOKEN_SIZE, decrypt_token, 0);

    /* construct HWID */
    byte[] hwid = this.generate_hwid();

    /* generate signature for a buffer of token and HWId */
    System.arraycopy(decrypt_token, 0, sealed_buffer, 0, LICENCE_TOKEN_SIZE);
    System.arraycopy(hwid, 0, sealed_buffer, LICENCE_TOKEN_SIZE, LICENCE_HWID_SIZE);

    out_sig = secure.sign(this.licence_sign_key, 16, 16, sealed_buffer, sealed_buffer.length);

    /* deliberately break signature if licencing disabled */
    if (!options.use_real_license_signature) {
        out_sig = new byte[LICENCE_SIGNATURE_SIZE]; // set to 0
    }

    /* now crypt the hwid */
    System.arraycopy(this.licence_key, 0, crypt_key, 0, this.licence_key.length);
    rc4_licence.init(true, new KeyParameter(crypt_key));
    rc4_licence.processBytes(hwid, 0, LICENCE_HWID_SIZE, crypt_hwid, 0);

    this.send_authresp(out_token, crypt_hwid, out_sig);
}