Firebase“MD5”& BloddyCrytpo不匹配

时间:2017-07-18 18:39:31

标签: actionscript-3 flash firebase firebase-storage

我正在尝试检查用户是否有本地文件。如果用户这样做,我会bloodycrypto从中获取md5。然后我比较这两个值。一个来自firebase文件的元数据,另一个来自文件的字节数组被消化。他们从不匹配。在尝试生成我上传的文件的md5时,Firebase会做些不同的事情吗?

sf = "You clicked on {0}x{1}".format(item.column(), item.row())

经过仔细检查(感谢Organis),firebase不会返回合适的MD5。它是什么?在我的存储控制台中,我没有看到md5属性,所以这是自动生成的吗?这些文件是通过基于my rest API指南的phantom's上传的。

更新:关注Organis对Firebase handle's MD5s

的评论
    private function handleMetaSuccess(e:StorageReferenceEvent):void 
    {
        trace("Meta succes for reference:" + this.name);
        storageMetaData = e.metadata;
        trace("reading file.");
        fileBA = new ByteArray();
        var fs:FileStream = new FileStream();
            fs.open(Definitions.CACHE_DIRECTORY.resolvePath(name + ".jpg"), FileMode.READ)
            fs.readBytes(fileBA);
            fs.close();

            var byteHash:String = MD5.hashBytes(fileBA)

            trace("Local hash = " + byteHash); //93b885adfe0da089cdf634904fd59f71
            trace("Network hash = " + storageMetaData.md5Hash); //bo7XPotC+T5wmAcpagnXBw==
            if (byteHash != storageMetaData.md5Hash)
            {
                trace("Not equal. Getting file."); //Always happens
                getFile();
            }
            else
            {
                loadFile();
            }
    }

尝试获取md5并将其转换为base64会导致一致的不匹配结果。当我尝试解码所有内容时,是否存在我遗漏或错误应用的争论?

1 个答案:

答案 0 :(得分:1)

  

...所以我会做类似

的事情
var storageHash:String = Base64.decode(storageMetaData.md5Hash).toString();
     

跟你的例子对吗?

请尝试以下代码,以便从Base64正确解码storageMetaData.md5Hash

让我知道trace("storage hash : " + storageHash);的结果,以检查您是否获得了32个十六进制值的(预期)序列。

private function handleMetaSuccess(e:StorageReferenceEvent):void 
{
    trace("Meta succes for reference:" + this.name);
    storageMetaData = e.metadata;
    trace("reading file.");
    fileBA = new ByteArray();
    var fs:FileStream = new FileStream();
    fs.open(Definitions.CACHE_DIRECTORY.resolvePath(name + ".jpg"), FileMode.READ)
    fs.readBytes(fileBA);
    fs.close();

    var byteHash:String = MD5.hashBytes(fileBA); //Local hash

    var ba_storageHash:ByteArray = new ByteArray();
    ba_storageHash = Base64.decode(storageMetaData.md5Hash); //update ByteArray
    var storageHash:String = bytesToHexString(ba_storageHash); //Hex values of bytes shown as String


    trace("Network hash : " + storageMetaData.md5Hash); //bo7XPotC+T5wmAcpagnXBw==
    trace("Local hash   : " + byteHash); //93b885adfe0da089cdf634904fd59f71
    trace("storage hash : " + storageHash); //what is result??

    if (byteHash != storageHash)
    {
        trace("Not equal. Getting file."); //Always happens
        getFile();
    }
    else
    {
        loadFile();
    }
}

// # Byte values (Hex) shown as (returned) String type
private function bytesToHexString(input:ByteArray) : String
{
    var strOut:String = ""; var strRead:String = "";
    input.position = 0;
    var intBASize:uint = input.length;

    for (var i:int = 0; i < intBASize; i++)
    {
        strRead = input.readUnsignedByte().toString(16); 

        if(strRead.length < 2) { strRead = "0" + strRead; } //# do padding
        strOut += strRead ;     
    }

    return strOut.toLowerCase(); //strOut.toUpperCase();
}