In a recent project I was to create a web service that would be consumed by another application. One of the requirements was to have a key in the service that authenticated the request as valid. But this key must never be the same and the key should be invalid soon after its use.This is the code I wrote to that purpose.public static bool isKeyValid(long testKey){    var k = GetKey();    var allowedVariance = 0.00000000004;    var variance = k * allowedVariance;    return (k + variance >= testKey && k - variance <= testKey);}public static long GetKey(){    var i = (long)DateTime.UtcNow.Ticks * 5;    var d = (long)Math.Sqrt(Math.Ceiling(400 - (DateTime.UtcNow.Day * Math.PI)));    var k = (long)((Math.Round((Math.Sqrt(i) * Math.Pow(Math.PI + d, 3)) * Math.E - d)) * d) + DateTime.UtcNow.Minute;    return k;}The point being that the caller generates a key and the receiver generates its own and then compares these two and says everything is ok if the difference is within a given variance.Note that nothing in the message is really secret and this is just a simple check so that the request is probably from a valid source.I have two questions for this. How could I have done this better in terms of existing encryptionlibraries (in .Net) or using other things such as certificates. This must work     cross platform (Windows, iOS, and Android devices)How can the given code be modified or improved to make it better forthe intended purpose?
One time key for authentication
c#;validation;api;cryptography