美文网首页
MD5的几种实现

MD5的几种实现

作者: 小晨主 | 来源:发表于2017-09-23 15:44 被阅读0次

PHP的实现

# 示例一

    echo md5('hello'); 
    
    // 结果为:5d41402abc4b2a76b9719d911017c592

Nodejs的实现

# 示例一

    let str = "hello";
    const crypto = require('crypto');
    let res = crypto.createHash('md5').update(str).digest("hex");
    console.log(res);

    // 结果:5d41402abc4b2a76b9719d911017c592

Python的实现

# 示例一

    # encoding: utf-8
    import md5
       
    m = md5.new()   
    m.update('hello')   
    print m.hexdigest()

    // 结果:5d41402abc4b2a76b9719d911017c592

# 示例二

    # encoding: utf-8
    import hashlib   
    
    m = hashlib.md5()   
    m.update('hello')   
    print m.hexdigest()

    // 结果:5d41402abc4b2a76b9719d911017c592

Golang的实现

# 示例一

    package main
    import (
        "crypto/md5"
        "fmt"
        "encoding/hex"
    )
    
    func main(){
        md5Ctx := md5.New()
        md5Ctx.Write([]byte("hello"))
        cipherStr := md5Ctx.Sum(nil)
        fmt.Print(hex.EncodeToString(cipherStr))
    }

    // 结果:5d41402abc4b2a76b9719d911017c592

相关文章

网友评论

      本文标题:MD5的几种实现

      本文链接:https://www.haomeiwen.com/subject/mducextx.html