English 中文(简体)
如何在WinCrypt生成和使用公用钥匙加密
原标题:How to generate and use public key cryptography in WinCrypt

目前,Im正在试验视窗加密软件,并处理一些涉及公共-地质学的问题。 我可以找到许多实例,说明如何加密物品,但并不直接涉及开端到确定的公共关键模式。

我在此粗略地概述了我目前的法典如何产生加密钥匙,我删除了可读性校正代码错误。

// MAKE AN RSA PUBLIC/PRIVATE KEY:
    CryptGenKey(hProv, CALG_RSA_KEYX, CRYPT_EXPORTABLE, &hKey);

// NOW LET S EXPORT THE PUBLIC KEY:
    DWORD keylen;
    CryptExportKey(hKey,0,PUBLICKEYBLOB,0,NULL,&keylen);
    LPBYTE KeyBlob;
    KeyBlob = (LPBYTE)malloc(keylen);
    CryptExportKey(hKey,NULL,PUBLICKEYBLOB,0,KeyBlob,&keylen);
    ofstream outputkey;
    outputkey.open("TestPublicKey.txt", ios_base::out | ios_base::binary);
    for(size_t i=0; i &lt keylen; ++i)
        outputkey&lt&ltKeyBlob[i];
    outputkey.close();
    free(KeyBlob);

// NOW LET S EXPORT THE PRIVATE KEY:
    CryptExportKey(hKey, 0, PRIVATEKEYBLOB,0,NULL,&keylen);
    KeyBlob = (LPBYTE)malloc(keylen);
    CryptExportKey(hKey,NULL,PRIVATEKEYBLOB,0,KeyBlob,&keylen)
    outputkey.open("TestPrivateKey.txt", ios_base::out | ios_base::binary);
    for(size_t i=0;i&ltkeylen;++i)
        outputkey&lt&ltKeyBlob[i];
    outputkey.close();
    free(KeyBlob);

// ENCRYPT A (SHORT) TEST MESSAGE [SHOULD JUST BE ANOTHER ALG S KEY LATER]:
    DWORD encryptBufferLen=0;
    CryptEncrypt(hKey, 0, true, 0, NULL, &encryptBufferLen, 0); // how much space?
    BYTE* encryptionBuffer = (BYTE*)malloc(encryptBufferLen);
    memcpy(encryptionBuffer, TestMessage, TestMessageLen); // move for in-place-encrypt
    CryptEncrypt(hKey,0,true,0, encryptionBuffer, &bufferlen, encryptBufferLen );

    ofstream message;
    message.open("Message.txt", ios_base::out | ios_base::binary);
    for(size_t i=0;i&ltencryptBufferLen;++i)
        message&lt&ltencryptionBuffer[i];
    message.close();

我的两个出口钥匙是不同的,但两者都能够在没有其他钥匙装上的情况下去加密信息。 此外,如果我在新的一届会议上对出口公用钥匙装上新电文,我仍然可以将其与其中任何一个钥匙脱钩。

谁能告诉我我,我会做什么错误或失踪? 我完全走错的道路吗?

问题回答

我不完全理解你提出的问题。 但总体情况

  1. 您并不直接使用公用钥匙加密数据。

  2. 在加密过程中: 您利用会议/测量/私人钥匙进行加密数据。 本届会议的关键随后由AT_EXCHANGE公用钥匙加密。

  3. 在加密过程中: AT_EXCHANGE私人钥匙将使会议钥匙脱节。 而本届会议的关键将用于对实际数据进行加密。

我不是这种加密的 expert子的专家! 但是,我此时正为此而努力,以便感受到你们的痛苦。

有些人看着加密轨道的裂痕。

// ENCRYPT A (SHORT) TEST MESSAGE [SHOULD JUST BE ANOTHER ALG S KEY LATER]:
DWORD encryptBufferLen=0;
CryptEncrypt(hKey, 0, true, 0, NULL, &encryptBufferLen, 0); // how much space?
BYTE* encryptionBuffer = (BYTE*)malloc(encryptBufferLen);
memcpy(encryptionBuffer, TestMessage, TestMessageLen); // move for in-place-encrypt
CryptEncrypt(hKey,0,true,0, encryptionBuffer, &bufferlen, encryptBufferLen );

看来,你要求你履行赋予你加密电文的大小功能,以便你能够分配其记忆,即大小。 你们不会在钥匙本身之外走过任何东西,这样我就认为它能够肯定地提供这些信息。

您有:CryptEncode(hKey, 0, real, 0, NUL, &encodeBufferLen, 0); /但为什么“NUL”在你实际上应当穿透的缓冲地带,其中要加以加密,这样,它就可以缩小规模,将其交还给你! 然后,你可以走下去。 我知道,出口轨道是如何运作的(因为你在这方面与关键部门合作),而你正在处理实际信息。 穿过参数,看看如何去?

我认为,你发现,你实际上无法与两个钥匙脱轨,因为你实际上没有加密任何东西? 我认为,你将电文加密为零规模的缓冲。

正如我不是一位专家所说的那样,我看不见...... 奇怪的是,我发现你在另一天担任了职务,并收获了帮助我理解的工作轨道,因此,我确实希望,这一信息有助于你!

Go through the links below provided by microsoft

你们是否在这两个关键方面使用CryptImportKey? 看起来像你的加密一样,只是把手法运用到你产生的钥匙上。 正确做公共/私人奶制品,你应当只向公共钥匙出口,并向需要的人出口。 虽然这是真正的“加密”,但此人知道它的方式是你们的。





相关问题
Extend Contacts application on Android to provide encryption

I want to encrypt individual contacts stored by the Contacts application on Android based on user s preference. So, I am thinking I ll have to hook/extend the Contacts application before the it stores ...

Make md5 strong

Im making a website that will intergrate with game that only support md5 hashing metod (atm). Which ofc is not especially safe anymore. But how could i make it stronger? Should I just generate long ...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I m essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a ...

Thread & Queue vs Serial performance

I though it ll be interesting to look at threads and queues, so I ve written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I m still very new ...

Convert PHP encryption code to C#

I m trying to convert this piece of code from PHP to C#. It s part of a Captive Portal. Could somebody explain what it does? $hexchal = pack ("H32", $challenge); if ($uamsecret) { $newchal = ...

Encryption: how to have 1 iv despite multiple fields

I ve been stuck trying to arrive at a best solution for this for a while. I know that an initialization vector has to be unique for each item being encrypted. So if I m encrypting an address and I ...

热门标签