/** * 调用rc4获得initKey * <br> (非 Javadoc) */ public void BuildComplexKey() { // 考虑到非极端恶劣线程队列堵塞现象 //这个过程无需加锁. //但如果一定要处理极端情况请按需对此过程进行加锁 this.complexKey = RC4.GetComplexKey(clientKey + serverKey); this.inputCounter = 0; this.outputCounter = 0; this.refresh = false; }
public static byte[] DecRC4(byte[] src) { int len = GetDecRC4Len(src); if (len < 3) { return(null); } byte[] body = new byte[len]; //读取消息体 Buffer.BlockCopy(src, 4, body, 0, len); //解密消息体 body = RC4.Convert(body, 4); return(body); }
public static int GetDecRC4Len(byte[] src) { CustomRC4Key key = CustomRC4Key.CreateCustomRC4Key(); byte[] blen = new byte[4]; blen[0] = src[0]; blen[1] = src[1]; blen[2] = src[2]; blen[3] = src[3]; blen = RC4.Convert(blen, 0); //key.InputCounterIncrease(blen.Length); byte[] rblen = new byte[4]; rblen[0] = blen[3]; rblen[1] = blen[2]; rblen[2] = blen[1]; rblen[3] = blen[0]; return(BitConverter.ToInt32(rblen, 0)); }
/** * 调用rc4 * <br> (非 Javadoc) * @param key */ public void BuildDefaultKey(String key) { this.complexKey = RC4.GetComplexKey(key); this.refresh = false; }
public static byte[] Convert(byte[] buff, int pos) { return(RC4.RC4Custom(buff, RC4.GetComplexKey(_key), pos)); }