小编sof*_*ess的帖子

如何导出使用 CryptoAPI 派生的 AES 密钥

我想使用 Windows CryptoAPI 函数进行 AES 加密。

众所周知,API有很多功能可以创建、散列和更改输入的密钥;它派生出密钥,您就可以处理它。

我的问题是我想知道派生密钥是什么?

#include <Windows.h>
#include <stdio.h>

int main()
{
    HCRYPTPROV hProv = 0;
    HCRYPTKEY hKey = 0;
    HCRYPTHASH hHash = 0;
    DWORD dwCount = 5;
    BYTE  rgData[512] = {0x01, 0x02, 0x03, 0x04, 0x05};
    LPWSTR wszPassword = L"pass";
    DWORD cbPassword = (wcslen(wszPassword)+1)*sizeof(WCHAR);

    if(!CryptAcquireContext(
        &hProv, 
        NULL,  
        MS_ENH_RSA_AES_PROV, 
        PROV_RSA_AES, 
        CRYPT_VERIFYCONTEXT))
    {
        printf("Error %x during CryptAcquireContext!\n", GetLastError());
        goto Cleanup;
    }

    if(!CryptCreateHash(hProv, CALG_SHA_256, 0, 0, &hHash)) 
    { 
        printf("Error %x during CryptCreateHash!\n", GetLastError());
        goto Cleanup;
    } 

    if(!CryptHashData(hHash, (PBYTE)wszPassword, …
Run Code Online (Sandbox Code Playgroud)

c encryption cryptography aes cryptoapi

5
推荐指数
1
解决办法
2455
查看次数

转换为double和back的BigInteger/BigRational问题

也许我不明白如何使用这两种类型:BigInteger/BigRational,但一般来说我想实现这个方程式: 在此输入图像描述

这是我的数据:n = 235,K = 40,这个小p(实际上称为rho)是5.一开始问题出现在Power函数中:结果非常非常大 - 所以这就是为什么我使用BigInteger库.但后来我意识到会有一个分区,结果将是一些双重类型 - 所以我改为BigRational库.

这是我的代码:

static void Main(string[] args)
    {
        var k = 40;
        var n = 235;
        var p = 5;

        // the P(n) equation
        BigRational pnNumerator = BigRational.Pow(p, n);
        BigRational pnDenominator = BigRational.Pow(k, (n - k)) * Factorial(k);


        // the P(0) equation

        //---the right side of "+" sign in Denominator
        BigRational pk = BigRational.Pow(p, k);
        BigRational factorialK = Factorial(k);
        BigRational lastPart = (BigRational.Subtract(1, (double)BigRational.Divide(p, k)));
        BigRational factorialAndLastPart = BigRational.Multiply(factorialK, lastPart);
        BigRational fullRightSide …
Run Code Online (Sandbox Code Playgroud)

c# biginteger

2
推荐指数
1
解决办法
1432
查看次数

标签 统计

aes ×1

biginteger ×1

c ×1

c# ×1

cryptoapi ×1

cryptography ×1

encryption ×1