计算 Md5 值获得 128 位数字,这个改如何获得?
发布于 4 年前 作者 myu 9150 次浏览 来自 问答

文件 md5 摘要,计Md5 值获得 128 位数字,对该数字进行 base64 编码

代码如下,我通过wx.getFileInfo获得了图片的md5值,但是如何计算 Md5 值获得 128 位数字?
wx.chooseImage({
            count1,
            sizeType: ['original''compressed'],
            sourceType: ['album''camera'],
            successres => {
                let imgUrl = res.tempFilePaths[0];
                 wx.getFileSystemManager().readFile({
                     filePath: res.tempFilePaths[0],
                    
                     successres1 => {
                       console.log('data:image/png;base64,' , res1)
                       imgbase64 = res1
                   
                     }
                   })

                wx.getFileInfo({
                    filePath: imgUrl,
                    digestAlgorithm"md5",
                    successres2 => {
                        console.log("md5", res2)
                        console.log("md5", res2.digest)
                        //md5.digest()
                        var data2 = this.hexToBytes(res2.digest)
                        console.log(data2)

                      
                        var hash = md5.base64(imgbase64)
                        console.log("hashmd5", hash)
                        let bizContent = {
                            'fileName'this.data.evidence.name,
                            'fileSize': res2.size,
                            'contentType'"image/jpeg",
                            'contentMD5': hash,
                        }
                 
                })

            }
        })
回到顶部