public Signature(UInt32 overlay, string transactionId, byte[] messageContents, SignerIdentity signerIdentity, ReloadConfig config) { m_ReloadConfig = config; algorithm = new SignatureAndHashAlgorithm(HashAlgorithm.sha256, ReloadGlobals.SignatureAlg); identity = signerIdentity; /* Compute signature */ byte[] bOverlay = BitConverter.GetBytes(overlay); byte[] bTransId = Encoding.Unicode.GetBytes(transactionId); byte[] bId = Encoding.Unicode.GetBytes(identity.ToString()); byte[] sig = new byte[bOverlay.Length + bTransId.Length + messageContents.Length + bId.Length]; System.Buffer.BlockCopy(bOverlay, 0, sig, 0, bOverlay.Length); System.Buffer.BlockCopy(bTransId, 0, sig, bOverlay.Length, bTransId.Length); System.Buffer.BlockCopy(messageContents, 0, sig, bOverlay.Length + bTransId.Length, messageContents.Length); System.Buffer.BlockCopy(bId, 0, sig, bOverlay.Length + bTransId.Length + messageContents.Length, bId.Length); signatureValue = Sign(sig); }
/// <summary> /// Each StoredData element is individually signed. However, the /// signature also must be self-contained and cover the Kind-ID and /// Resource-ID even though they are not present in the StoredData /// structure. The input to the signature algorithm is: /// resource_id || kind || storage_time || StoredDataValue || /// SignerIdentity /// </summary> /// <param name="resId"></param> /// <param name="kind"></param> /// <param name="storageTime"></param> /// <param name="storedDataValue"></param> /// <param name="identity"></param> public Signature(ResourceId resId, UInt32 kind, UInt64 storageTime, StoredDataValue value, SignerIdentity signerIdentity, ReloadConfig config) { m_ReloadConfig = config; var ascii = new ASCIIEncoding(); /* Set alogorithm and identity */ algorithm = new SignatureAndHashAlgorithm(HashAlgorithm.sha256, ReloadGlobals.SignatureAlg); identity = signerIdentity; /* Get string of stored data value */ var ms = new MemoryStream(); var bw = new BinaryWriter(ms); value.Dump(bw); value.GetUsageValue.dump(bw); ms.Position = 0; var sr = new StreamReader(ms); string strValue = sr.ReadToEnd(); sr.Close(); bw.Close(); /* Concatenate signature input */ String signaturInput = String.Format("{0}{1}{2}{3}{4}", ascii.GetString(resId.Data, 0, resId.Data.Length), kind, storageTime, strValue, identity.ToString()); signatureValue = Sign(signaturInput); }
/// <summary> /// For signatures over messages the input to the signature is computed /// over the overlay and transaction_id come from the forwarding header /// see RELOAD base -13 p.53 /// </summary> /// <param name="overlay">overlay</param> /// <param name="transaction_id">transaction_id</param> /// <param name="messageContents">Message Contents</param> /// <param name="signerIdentity">SignerIdentity</param> public Signature(UInt32 overlay, string transactionId, string messageContents, SignerIdentity signerIdentity, ReloadConfig config) { m_ReloadConfig = config; algorithm = new SignatureAndHashAlgorithm(HashAlgorithm.sha256, ReloadGlobals.SignatureAlg); identity = signerIdentity; /* Compute signature */ String signaturInput = String.Format("{0}{1}{2}{3}", overlay, transactionId, messageContents, identity.ToString()); signatureValue = Sign(signaturInput); }