// rc5 加密后大小不会变化的 static public bool RC5_ECB_Symmetry_Encode_Byte(byte[] encryptByte, uint startPos, uint inLen, ref byte[] outBytes, RC5_32_KEY rgbKey, CryptContext cryptContext) { try { RC5.RC5_32_ecb_encrypt_one(encryptByte, startPos, inLen, ref outBytes, rgbKey, RC5.RC5_ENCRYPT, cryptContext); return true; } catch { Ctx.m_instance.m_logSys.error("RC5_ECB_Symmetry_Encode_Byte error"); return false; } }
protected void testRc5() { string testStr = "asdfasdf5"; //byte[] inBytes = System.Text.Encoding.UTF8.GetBytes(testStr); byte[] inBytes = { 0x3f, 0x79, 0xd5, 0xe2, 0x4a, 0x8c, 0xb6, 0xc1, 0x3f, 0x79, 0xd5, 0xe2, 0x4a, 0x8c, 0xb6, 0xc1 }; byte[] outBytes = new byte[8]; uint inSize = (uint)inBytes.Length; RC5_32_KEY rc5Key = new RC5_32_KEY(); // RC5 key RC5.RC5_32_set_key(rc5Key, 16, Crypt.RC5_KEY, RC5.RC5_12_ROUNDS); // 生成秘钥 CryptContext cryptContext = new CryptContext(); Crypt.encryptData(inBytes, 0, 16, ref outBytes, cryptContext); Crypt.decryptData(outBytes, 0, 16, ref inBytes, cryptContext); testStr = System.Text.Encoding.Default.GetString(inBytes); }
static public bool RC5_ECB_Symmetry_Decode_Byte(byte[] decryptByte, uint startPos, uint inLen, ref byte[] outBytes, RC5_32_KEY rgbKey, CryptContext cryptContext) { try { RC5.RC5_32_ecb_encrypt_one(decryptByte, startPos, inLen, ref outBytes, rgbKey, RC5.RC5_DECRYPT, cryptContext); return(true); } catch { Ctx.m_instance.m_logSys.error("RC5_ECB_Symmetry_Decode_Byte error"); return(false); } }