【计算apk的checksum】

计算apk的checksum方法

在这里插入图片描述

方法1:

def test_count_apk_checksum(server_checksum):
    print('\ntest_count_apk_checksum===')
    with open('c_download/app_download.apk', 'rb') as f:
        m = hashlib.new('SHA256', f.read()).hexdigest()       # read file by file object
        if server_checksum == m:
            print('server_checksum: ', server_checksum)
            print('count_checksum: ', m)
            print('app download success')
        else:
            print('server_checksum: ', server_checksum)
            print('count_checksum: ', m)
            print('app download failed')

方法2:

def test_count_apk_checksum(server_checksum):
    print('\ntest_count_apk_checksum===')
    with open('c_download/app_download.apk', 'rb') as f:
        m = hashlib.sha256(f.read()).hexdigest()        # read file by file object
        if server_checksum == m:
            print('server_checksum: ', server_checksum)
            print('count_checksum: ', m)
            print('app download success')
        else:
            print('server_checksum: ', server_checksum)
            print('count_checksum: ', m)
            print('app download failed')

方法3:

def test_count_apk_checksum(server_checksum):
    print('\ntest_count_apk_checksum===')
    with open('c_download/app_download.apk', 'rb') as f:
        m = hashlib.sha256()
        m.update(f.read())
        value_checksum = m.hexdigest()
        if server_checksum == value_checksum :
            print('server_checksum: ', server_checksum)
            print('count_checksum: ', value_checksum )
            print('app download success')
        else:
            print('server_checksum: ', server_checksum)
            print('count_checksum: ', value_checksum )
            print('app download failed')

注意:

1.如果读取文件,不能直接放入文件的路径进行读入,否则计算的checksum值会是错误的,必须换成file的对象来读取
如:

def test_count_apk_checksum(server_checksum):
    print('\ntest_count_apk_checksum===')
    with open('c_download/app_download.apk', 'rb') as f:
        m = hashlib.new('SHA256', **b'c_download/app_download.apk'**).hexdigest()     # this method is not fit for reading file
        # m = hashlib.sha256(**'c_download/app_download.apk'**.encode()).hexdigest()    # this method is not fit for reading file
        if server_checksum == m:
            print('server_checksum: ', server_checksum)
            print('count_checksum: ', m)
            print('app download success')
        else:
            print('server_checksum: ', server_checksum)
            print('count_checksum: ', m)
            print('app download failed')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值