Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Triple DES
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Net.Sockets; using System.Net; using System.Security.Cryptography; namespace Rextester { /// <summary> /// Summary description for Class1 /// </summary> static class Program { public static void Main(string[] args) { System.Console.WriteLine(CalcMac("C67DDB0CE47D27FAF6F32ECA5C99E8AF", "foobar")); } static string CalcMac(string sKey, string sData) { byte[] bKey = HexToBytes(sKey); byte[] bMsg = HexToBytes(sData); byte[] iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; DESCryptoServiceProvider des = new DESCryptoServiceProvider(); des.Padding = PaddingMode.Zeros; des.Mode = CipherMode.CBC; byte[] bK1 = new byte[8]; for (int i = 0; i < 8; i++) bK1[i] = bKey[i]; byte[] bK2 = new byte[8]; for (int i = 0; i < 8; i++) bK2[i] = bKey[i + 8]; ICryptoTransform ict1 = des.CreateEncryptor(bK1, iv); byte[] bFt = ict1.TransformFinalBlock(bMsg, 0, bMsg.Length); byte[] bLCb = new byte[8]; for (int i = 0; i < 8; i++) bLCb[i] = bFt[i + bFt.Length - 8]; des.Mode = CipherMode.ECB; ICryptoTransform ict1_5 = des.CreateDecryptor(bK2, iv); bLCb = ict1_5.TransformFinalBlock(bLCb, 0, bLCb.Length); ICryptoTransform ict2 = des.CreateEncryptor(bK1, iv); byte[] bMac = ict2.TransformFinalBlock(bLCb, 0, bLCb.Length); return ToHex(bMac); } public static string ToHex(this byte[] bytes) { char[] c = new char[bytes.Length * 2]; byte b; for (int bx = 0, cx = 0; bx < bytes.Length; ++bx, ++cx) { b = ((byte)(bytes[bx] >> 4)); c[cx] = (char)(b > 9 ? b + 0x37 : b + 0x30); b = ((byte)(bytes[bx] & 0x0F)); c[++cx] = (char)(b > 9 ? b + 0x37 : b + 0x30); } return new string(c); } public static byte[] HexToBytes(this string str) { if (str.Length == 0 || str.Length % 2 != 0) throw new Exception("String length must be even"); byte[] buffer = new byte[str.Length / 2]; char c; for (int bx = 0, sx = 0; bx < buffer.Length; ++bx, ++sx) { // Convert first half of byte c = str[sx]; buffer[bx] = (byte)((c > '9' ? (c > 'Z' ? (c - 'a' + 10) : (c - 'A' + 10)) : (c - '0')) << 4); // Convert second half of byte c = str[++sx]; buffer[bx] |= (byte)(c > '9' ? (c > 'Z' ? (c - 'a' + 10) : (c - 'A' + 10)) : (c - '0')); } return buffer; } } }
run
|
edit
|
history
|
help
0
Factorial using Recursion
Calculadora
Enum.IsDefined
PermuteAString
Word count in string
Cenforce 100 mg
TEST 1
Linq join to tables
1
Easy prgm