On Thu, Oct 18, 2001 at 10:59:25AM -0500, Nathan E Norman wrote: > On Thu, Oct 18, 2001 at 01:58:10PM +0200, martin f krafft wrote: > > goal: a 4-16 byte 7-bit character value that somehow encodes the time > > of creation such that it can be extracted if the encoding scheme/seed > > is known. the encoded value should be such that it is mostly > > impossible to change it so as to yield a later time of creation to be > > encoded. in general, changing the encoded value may well render the > > data invalid. > > > > this is supposed to be a token that's valid for a limited amount of > > time, after which, a new token has to be fetched. this token should > > not be obvious (e.g. the timestamp) to prevent people from changing > > it to be valid longer rather than fetching a new one. > > > > can you do it? or is there a tool out there? > > use perl, Digest::HMAC_MD5 to encode the token, and MIME::Base64 to > make the result HTTP palatable. > > I used this to write a cookie-based web authentication scheme which > timed out after some period of inactivity. I'll look around for the > code as it sounds like you're doing something similar. > > libdigest-hmac-perl contains Digest::HMAC_MD5 > libmime-base64-perl contains MIME::Base64
also, if *tamper*-protecting the timestamp is your primary intention, you might find the related section of the book "Writing Apache Modules with Perl and C" from O'Reilly (often referred to as the "Eagle book") a useful read. Luckily, the relevant chapter of this very fine book is available online: http://www.modperl.com/book/chapters/ch6.html#Cookie_Based_Access_Control It explains the basic principles of using hash functions (MD5) to protect snippets of data against modification, like your expiration date, etc... The essential idea is to incorporate a secret key when computing the checksum -- in its most simple form something like the following pseudo code: $hash = md5sum( "$secret$data" ) $ticket = "$data$hash" To verify the validity of the ticket, just seperate the data and hash part, and check whether the hash matches the real one which *only you* can compute using your secret key (as shown above). As hashes like MD5 are *one-way* functions, it's infeasible (within the general limits of cryptography) to reverse the operation to obtain your secret key. Of course, many variations on the theme exist... Actually, this is a quite common technique in the context of web authentication/authorization, so, of course, there are various utilities to make your life easier. I'd suggest that you flip through the pages of the mentioned docs -- it might save you from reinventing the wheel ;) Cheers -- Erdmut Pfeifer science+computing ag -- Bugs come in through open windows. Keep Windows shut! --