/// <summary> /// Sets the algorithm. /// </summary> /// <param name="data">The input data.</param> /// <param name="record">The record.</param> private static void SetAlgorithm(DsInputData data, DSRecord record) { if (Enum.IsDefined(typeof(DSAlgorithm), Convert.ToInt32(data.Algorithm))) { record.Algorithm = (DSAlgorithm)data.Algorithm; } else { record.Algorithm = DSAlgorithm.None; } }
/// <summary> /// Calculates ds records from input data. /// </summary> /// <param name="data">The input data.</param> /// <returns> /// list of ds records. /// </returns> public DSRecord CalculateRecord(DsInputData data) { var recordDs = new DSRecord(); byte[] inputData = GetInputData(data); SetSha1Data(inputData, recordDs, data); SetAlgorithm(data, recordDs); SetSha256Data(inputData, recordDs); SetKey(data, recordDs); return(recordDs); }
/// <summary> /// Sets the sha256 data. /// </summary> /// <param name="inputData">The input data.</param> /// <param name="record">The record.</param> private static void SetSha256Data(byte[] inputData, DSRecord record) { byte[] sha256Hash; using (SHA256 sha256 = SHA256Cng.Create()) { sha256Hash = sha256.ComputeHash(inputData); } record.DigestField256Text = sha256Hash.ToHexString(); record.DigestField256 = sha256Hash; record.DigestType256 = DigestType.Sha256; }
/// <summary> /// Sets the sha1 data. /// </summary> /// <param name="inputData"> /// The input data. /// </param> /// <param name="record"> /// The record. /// </param> /// <param name="data"> /// The input ds data. /// </param> private static void SetSha1Data(byte[] inputData, DSRecord record, DsInputData data) { byte[] sha1Hash; using (SHA1 sha1 = SHA1Cng.Create()) { sha1Hash = sha1.ComputeHash(inputData); } record.DigestType = DigestType.Sha256; record.KeyTag = Calculate(GeRRData(data)); record.DigestFieldText = sha1Hash.ToHexString(); record.DigestField = sha1Hash; }
/// <summary> /// Calculates ds records from input data. /// </summary> /// <param name="list">The input data.</param> /// <returns> /// list of ds records. /// </returns> public IList <DSRecord> CalculateRecords(IList <DsInputData> list) { var records = new List <DSRecord>(); foreach (DsInputData data in list) { var recordDs = new DSRecord(); byte[] inputData = GetInputData(data); var test = inputData.ToHexString(); SetSha1Data(inputData, recordDs, data); SetAlgorithm(data, recordDs); SetSha256Data(inputData, recordDs); SetKey(data, recordDs); records.Add(recordDs); } return(records); }
/// <summary> /// Sets the key. /// </summary> /// <param name="data">The input data.</param> /// <param name="record">The record.</param> private static void SetKey(DsInputData data, DSRecord record) { record.DnsKey = data.DnsKey; }