encryption - What implementations allow me to detect failed HMAC validations to detect active attacks? -


i'm trying bring awareness around need authentication encryption using software alert , report on failed mac verification attempts, , sharing results middle management.

i'm not cryptographer, see value in proper implementation. ideally i'd create report says x attacks prevented.

is valid idea, or overly simplistic? if not, should start in implementing it? (low level aes, pgp, etc?)

here c# mac code sample modified alert or log when authentication fails. incomplete sample shouldn't used as-is since many other details need considered before implementing authenticate-then-encrypt (ate) or encrypt-then-authenticate (eta)

it nice know performance counter, log file, or dll exception relates error. i'll investigating bouncycastle see corresponding exception is.

// compares key in source file new key created data portion of file. if keys  // compare data has not been tampered with. public static bool verifyfile(byte[] key, string sourcefile) {     bool err = false;     // initialize keyed hash object.      using (hmacsha1 hmac = new hmacsha1(key))     {         // create array hold keyed hash value read file.         byte[] storedhash = new byte[hmac.hashsize / 8];         // create filestream source file.         using (filestream instream = new filestream(sourcefile, filemode.open))         {             // read in storedhash.             instream.read(storedhash, 0, storedhash.length);             // compute hash of remaining contents of file.             // stream positioned @ beginning of content,              // after stored hash value.             byte[] computedhash = hmac.computehash(instream);             // compare computed hash stored value              (int = 0; < storedhash.length; i++)             {                 if (computedhash[i] != storedhash[i])                 {                     err = true;                 }             }         }     }     if (err)     {         console.writeline("hash values differ! signed file has been tampered with!");         //          //          // <-------- mac alerting go         //          //           return false;     }     else     {         console.writeline("hash values agree -- no tampering occurred.");         return true;     }  } //end verifyfile 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -