Posted to tcl by patthoyts at Mon Feb 26 23:43:52 GMT 2007view raw
- # Requires some reliable and secret method to exchange the secret.
- package require blowfish
- package require base64
- package require md5
- proc CreateKey {secret} {
- return [blowfish::Init cbc $secret [string repeat \0 8]]
- }
- proc Enc {key data} {
- # shoud be the best random data you can get.
- set iv [string range [md5::md5 [clock clicks]:[pid]:[expr {rand()}]] 0 7]
- blowfish::Reset $key $iv
- set c [blowfish::Encrypt $key $data]
- return [base64::encode $iv$c]
- }
- proc Dec {key pkt} {
- set data [base64::decode $pkt]
- set iv [string range $data 0 7]
- set data [string range $data 8 end]
- blowfish::Reset $key $iv
- return [blowfish::Decrypt $key $data]
- }