static void Main(string[] args) { var data = new Data(); data.wireDecode(new Blob(TlvData)); // Use a hard-wired secret for testing. In a real application the signer // ensures that the verifier knows the shared key and its keyName. var key = new Blob(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); if (KeyChain.verifyDataWithHmacWithSha256(data, key)) Console.Out.WriteLine("Hard-coded data signature verification: VERIFIED"); else Console.Out.WriteLine("Hard-coded data signature verification: FAILED"); var freshData = new Data(new Name("/ndn/abc")); var signature = new HmacWithSha256Signature(); signature.getKeyLocator().setType(KeyLocatorType.KEYNAME); signature.getKeyLocator().setKeyName(new Name("key1")); freshData.setSignature(signature); freshData.setContent(new Blob("SUCCESS!")); Console.Out.WriteLine("Signing fresh data packet " + freshData.getName().toUri()); KeyChain.signWithHmacWithSha256(freshData, key); if (KeyChain.verifyDataWithHmacWithSha256(freshData, key)) Console.Out.WriteLine("Freshly-signed data signature verification: VERIFIED"); else Console.Out.WriteLine("Freshly-signed data signature verification: FAILED"); }
/// <summary> /// Create a new HmacWithSha256Signature with a copy of the fields in the given /// signature object. /// </summary> /// /// <param name="signature">The signature object to copy.</param> public HmacWithSha256Signature(HmacWithSha256Signature signature) { this.signature_ = new Blob(); this.keyLocator_ = new ChangeCounter( new KeyLocator()); this.changeCount_ = 0; signature_ = signature.signature_; keyLocator_.set(new KeyLocator(signature.getKeyLocator())); }
/// <summary> /// Create a new HmacWithSha256Signature with a copy of the fields in the given /// signature object. /// </summary> /// /// <param name="signature">The signature object to copy.</param> public HmacWithSha256Signature(HmacWithSha256Signature signature) { this.signature_ = new Blob(); this.keyLocator_ = new ChangeCounter( new KeyLocator()); this.changeCount_ = 0; signature_ = signature.signature_; keyLocator_.set(new KeyLocator(signature.getKeyLocator())); }