做58网站怎么赚钱,优秀的wordpress主题,河南网站排名优化价格,私域视频使用场景#xff1a;1、数据完整性校验#xff1a;下载文件时验证文件是否被篡改。2、密码存储#xff1a;将用户密码加密后存储#xff0c;防止明文泄露。3、数字签名#xff1a;用于验证签名和数据的完整性#xff0c;例如在区块链交易。4、数据索引#xff1a;在数据…使用场景1、数据完整性校验下载文件时验证文件是否被篡改。2、密码存储将用户密码加密后存储防止明文泄露。3、数字签名用于验证签名和数据的完整性例如在区块链交易。4、数据索引在数据库中用于快速查找和比较数据MD5MD5特点1、固定长度的字符串长度为32位2、md5得到的值一般都是十六进制数据取值范围a-f 0-93、md5是不可逆的如果对一串字符串进行md5的编码是无法回复成原来的字符串的4、md5可以完成数据的校验可以保证源数据不被篡改可以保证数据的一致性使用python实现的MD5编码import hashlib def md5_(string): md5 hashlib.md5() md5.update(string.encode(utf-8)) return md5.hexdigest() print(md5_(1))使用javascript实现的MD5编码const crypto require(crypto); function md5_(text) { return crypto.MD5(text).toString(); } console.log(md5_(1));SHA系列算法安全哈希算法是由美国国家安全局 NSA 设计主要适用于数字签名标准里面定义的数字签名算法SHA算法通常指SHA家族里面的五个算法SHA-1、SHA-224、SHA-256、SHA-384、SHA-512SHA是比MD5更安全一点的摘要算法MD5的密文是32位而SHA-1是40位版本越强密文越长代价就是速度越慢。使用python实现的SHA加密import hashlib def sha1(text): sha_obj hashlib.sha1() sha_obj.update(text.encode(utf-8)) return sha_obj.hexdigest() def sha224(text): sha_obj hashlib.sha224() sha_obj.update(text.encode(utf-8)) return sha_obj.hexdigest() def sha256(text): sha_obj hashlib.sha256() sha_obj.update(text.encode(utf-8)) return sha_obj.hexdigest() def sha384(text): sha_obj hashlib.sha384() sha_obj.update(text.encode(utf-8)) return sha_obj.hexdigest() def sha512(text): sha_obj hashlib.sha512() sha_obj.update(text.encode(utf-8)) return sha_obj.hexdigest() print(SHA1算法, sha1(1), 数据长度, len(sha1(1))) print(SHA224算法, sha224(1), 数据长度, len(sha224(1))) print(SHA256算法, sha256(1), 数据长度, len(sha256(1))) print(SHA384算法, sha384(1), 数据长度, len(sha384(1))) print(SHA512算法, sha512(1), 数据长度, len(sha512(1)))使用javascript实现的SHA加密const crypto require(crypto); // SHA1 算法实现 function sha1(data){ // return crypto.SHA1(1).toString() 也可以实现 const hash crypto.createHash(sha1); hash.update(data, utf8); return hash.digest(hex); } // SHA224 算法实现 function sha224(text) { // return crypto.SHA224(1).toString() 也可以实现 const hash crypto.createHash(sha224); hash.update(text, utf8); return hash.digest(hex); } // SHA256 算法实现 function sha256(text) { // return crypto.SHA256(1).toString() 也可以实现 const hash crypto.createHash(sha256); hash.update(text, utf8); return hash.digest(hex); } // SHA384 算法实现 function sha384(text) { // return crypto.SHA384(1).toString() 也可以实现 const hash crypto.createHash(sha384); hash.update(text, utf8); return hash.digest(hex); } // SHA512 算法实现 function sha512(text) { // return crypto.SHA512(1).toString() 也可以实现 const hash crypto.createHash(sha512); hash.update(text, utf8); return hash.digest(hex); } // 测试输出 console.log(SHA1算法, sha1(1), 数据长度, sha1(1).length); console.log(SHA224算法, sha224(1), 数据长度, sha224(1).length); console.log(SHA256算法, sha256(1), 数据长度, sha256(1).length); console.log(SHA384算法, sha384(1), 数据长度, sha384(1).length); console.log(SHA512算法, sha512(1), 数据长度, sha512(1).length);HMAC散列消息认证码该算法在1996年被提出1997年作为RFC2104被公布HMAC加密算法是一种基于安全加密Hash函数和共享密钥的消息认证协议。它要求通讯双方共享密钥key并指出某一种算法对报文Hash运算形成固定的长度的认证码。通讯双方通过认证码的校验来确定报文的合法性。python实现HMAC的编码import hmac def hmac_encode_md5(key, data): hmac_md5 hmac.new(key.encode(utf-8), data.encode(utf-8), digestmodmd5) return hmac_md5.hexdigest() def hmac_encode_sha1(key, data): hmac_sha1 hmac.new(key.encode(utf-8), data.encode(utf-8), digestmodsha1) return hmac_sha1.hexdigest() def hmac_encode_sha224(key, data): hmac_sha224 hmac.new(key.encode(utf-8), data.encode(utf-8), digestmodsha224) return hmac_sha224.hexdigest() def hmac_encode_sha256(key, data): hmac_sha256 hmac.new(key.encode(utf-8), data.encode(utf-8), digestmodsha256) return hmac_sha256.hexdigest() def hmac_encode_sha384(key, data): hmac_sha384 hmac.new(key.encode(utf-8), data.encode(utf-8), digestmodsha384) return hmac_sha384.hexdigest() def hmac_encode_sha512(key, data): hmac_sha512 hmac.new(key.encode(utf-8), data.encode(utf-8), digestmodsha512) return hmac_sha512.hexdigest() print(hmac_encode_md5(1, 1)) print(hmac_encode_sha1(1, 1)) print(hmac_encode_sha224(1, 1)) print(hmac_encode_sha256(1, 1)) print(hmac_encode_sha384(1, 1)) print(hmac_encode_sha512(1, 1))使用javascript实现HMAC编码const crypto require(crypto); // HMAC-MD5 实现 function hmacEncodeMd5(key, data) { return crypto.createHmac(md5, key).update(data).digest(hex); } // HMAC-SHA1 实现 function hmacEncodeSha1(key, data) { return crypto.createHmac(sha1, key).update(data).digest(hex); } // HMAC-SHA224 实现 function hmacEncodeSha224(key, data) { return crypto.createHmac(sha224, key).update(data).digest(hex); } // HMAC-SHA256 实现 function hmacEncodeSha256(key, data) { return crypto.createHmac(sha256, key).update(data).digest(hex); } // HMAC-SHA384 实现 function hmacEncodeSha384(key, data) { return crypto.createHmac(sha384, key).update(data).digest(hex); } // HMAC-SHA512 实现 function hmacEncodeSha512(key, data) { return crypto.createHmac(sha512, key).update(data).digest(hex); } // 测试输出 console.log(hmacEncodeMd5(1, 1)); console.log(hmacEncodeSha1(1, 1)); console.log(hmacEncodeSha224(1, 1)); console.log(hmacEncodeSha256(1, 1)); console.log(hmacEncodeSha384(1, 1)); console.log(hmacEncodeSha512(1, 1));