CRC32

Posted on 2020-04-05 23:57  努力成长静待花开  阅读(369)  评论(0编辑  收藏  举报

在与api交互中请求需提交文件的crc32 (循环冗余校验)

function Get-CRC32 {
    param(
        [Parameter(Mandatory = $False)]
        [Int]$InitialCRC = 0,
        [Parameter(Mandatory = $True)]
        [Byte[]]$Buffer
    )

    Add-Type -TypeDefinition @"
        using System;
        using System.Diagnostics;
        using System.Runtime.InteropServices;
        using System.Security.Principal;
    
        public static class CRC32
        {
            [DllImport("ntdll.dll")]
            public static extern UInt32 RtlComputeCrc32(
                UInt32 InitialCrc,
                Byte[] Buffer,
                Int32 Length);
        }
"@
    [CRC32]::RtlComputeCrc32($InitialCRC, $Buffer, $Buffer.Length)
}