public byte[] Hmac(byte[] data) { var hex = HexUtil.ByteArrayToString(data); var hamc = sdfHelper.SDF_HMAC(data); return(hamc); }
public void Send(AbstractSendablePacket packet) { packet.WriteBody(this); Logger.Debug("[發送封包] OPCODE: {0}(0x{1:X4}) ALL: {2}", Enum.GetName(typeof(PacketOpcode.SendPacketOpcode), packet.Opcode), packet.Opcode, HexUtil.ByteArrayToString(packet.toArray())); Session.Send(packet.toArray()); }
/// <summary> /// 加密口令 /// </summary> /// <param name="pass">sm2的数字信封</param> /// <param name="salt">盐(无效参数)</param> /// <param name="iterations">轮数(无效参数)</param> /// <returns></returns> public byte[] Encryption(byte[] pass, byte[] salt, int iterations) { var Hex = HexUtil.ByteArrayToString(pass); var Hexsalt = HexUtil.ByteArrayToString(salt); var result = cryptographyProvider.TransEncrypted(pass, salt); return(result); }
public void PDKDF2PasswordStoreTest() { var salt = HexUtil.StringToByteArray(hex); IPasswordStore passwordStore = new PDKDF2PasswordStore(); var enc = passwordStore.Encryption(Encoding.UTF8.GetBytes(password), salt, 1000 * 80); var text = HexUtil.ByteArrayToString(enc); Console.WriteLine(text); }
public override void WriteBody(MapleClient client) { Logger.Info("登入帳號: {0} 登入密碼: {1} Mac: {2}", client.Account, client.Passowrd, HexUtil.ByteArrayToString(client.MacAddress)); packet.WriteMapleString(client.Account); packet.WriteMapleString(client.Passowrd); packet.WriteBytes(client.MacAddress); }
public async void Sha256PasswordStoreTest() { var salt = HexUtil.StringToByteArray(hex); IPasswordStore passwordStore = new SHA256PasswordStore(); var enc = await passwordStore.Encryption(Encoding.UTF8.GetBytes(password), salt, 1000 *160); var text = HexUtil.ByteArrayToString(enc); Console.WriteLine(text); }
public byte[] SM2Decrypt(byte[] data) { var hex = HexUtil.ByteArrayToString(data); SM2Cipher sm2 = SM2Cipher.InsanceC1C3C2(data, false); var pucCipher = sm2.ToECCCipher(); var dec = sdfHelper.SM2_Decrypt(sm2, 11); return(dec); }
/// <summary> /// 验证口令 /// </summary> /// <param name="encryData">加密数据</param> /// <param name="pass">数字信封数据</param> /// <param name="salt">盐(无效参数)</param> /// <param name="iterations">轮数(无效参数)</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public bool VerifyPassword(byte[] encryData, byte[] pass, byte[] salt, int iterations) { var Hex = HexUtil.ByteArrayToString(pass); var Hexsalt = HexUtil.ByteArrayToString(salt); var result = cryptographyProvider.TransEncrypted(pass, salt); //将数据库中存储的加密口令与 用户输入的口令的加密的加密结果比较 var verify = SecurityUtil.SafeCompareByteArray(encryData, result); return(verify); }
public byte[] TransEncrypted(byte[] data, byte[] iv) { if (iv.Length != 16) { throw new ArgumentException("iv len !=16"); } var plain = SM2Decrypt(data); var hex = HexUtil.ByteArrayToString(plain); var hexIV = HexUtil.ByteArrayToString(iv); var enc = SM4Encrypt(plain, iv); var encHex = HexUtil.ByteArrayToString(enc); return(enc); }
public void HandlePacket(MapleClient client, PacketReader packet) { int opcode = packet.ReadShort(); if (recvPackets.ContainsKey(opcode)) { Logger.Debug("[接收封包] OPCODE: {0}(0x{1:X4}) ALL: {2}", Enum.GetName(typeof(PacketOpcode.SendPacketOpcode), opcode), opcode, HexUtil.ByteArrayToString(packet.ToArray())); recvPackets[opcode].HandlePacket(client, packet); } else { Logger.Warning("封包 OPCODE:{0} 未處理", String.Format("0x{0:X4}", opcode)); } }
/// <summary> /// 产生不可预测的Token /// </summary> /// <param name="tokenId">tokenId</param> /// <param name="tokenByteSize">不可预测部分的byte长度</param> /// <returns></returns> public static string GenerateToken(long tokenId, int tokenByteSize = 16) { if (tokenByteSize < 1) { tokenByteSize = 1; } //byte数组A 8字节 long tokenId //byte数组B tokenByteSize字节 随机生成 默认长度16 //AB拼接 输出hex字符串 using (RandomNumberGenerator rng = new RNGCryptoServiceProvider()) { byte[] numData = BitConverter.GetBytes(tokenId); byte[] randomData = new byte[tokenByteSize]; rng.GetBytes(randomData); byte[] tokenData = new byte[numData.Length + randomData.Length]; Array.Copy(numData, 0, tokenData, 0, numData.Length); Array.Copy(randomData, 0, tokenData, numData.Length, randomData.Length); // string token = Convert.ToBase64String(tokenData); string token = HexUtil.ByteArrayToString(tokenData); Console.WriteLine(); return(token); } }
public static string ByteArrayToHex(this byte[] data) { return(HexUtil.ByteArrayToString(data)); }