List of usage examples for org.bouncycastle.crypto.engines RC4Engine processBytes
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff)
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 w w . j ava2 s . c o 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);/* w ww . ja v a 2 s . c o 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.RC4Session.java
License:Apache License
private byte[] updateRc4Key(byte[] originalKey, byte[] currentKey) { int keySize = 0; switch (encryptionMethod) { case Constants.ENCRYPTION_128BIT: keySize = 16;/* ww w. j a v a 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: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/*www . j a v a 2 s . c o m*/ * * @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 w w w .j ava2 s. 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); }
From source file:net.propero.rdp.Licence.java
License:Open Source License
/** * Handle a licence issued by the server, save to disk if * options.save_licence//from w w w . j a va 2 s. c o m * * @param data * Packet containing issued licence */ public void process_issue(RdpPacket data) { int length = 0; int check = 0; RC4Engine rc4_licence = new RC4Engine(); byte[] key = new byte[this.licence_key.length]; System.arraycopy(this.licence_key, 0, key, 0, this.licence_key.length); data.incrementPosition(2); // unknown length = data.getLittleEndian16(); if (data.getPosition() + length > data.getEnd()) { return; } rc4_licence.init(false, new KeyParameter(key)); byte[] buffer = new byte[length]; data.copyToByteArray(buffer, 0, data.getPosition(), length); rc4_licence.processBytes(buffer, 0, length, buffer, 0); data.copyFromByteArray(buffer, 0, data.getPosition(), length); check = data.getLittleEndian16(); if (check != 0) { // return; } secure.licenceIssued = true; /* * data.incrementPosition(2); // in_uint8s(s, 2); // pad * // advance to fourth string length = 0; for (int i = 0; i < 4; i++) { * data.incrementPosition(length); // in_uint8s(s, length); length = * data.getLittleEndian32(length); // in_uint32_le(s, length); if * (!(data.getPosition() + length <= data.getEnd())) return; } */ secure.licenceIssued = true; LOGGER.debug("Server issued Licence"); if (options.save_licence) { save_licence(data, length - 2); } }