Question on Encryption and decryption in AES-GCM mode

Ji Shirley 181 Reputation points
2021-06-18T03:09:24.877+00:00

I follow the code in the link below to learn the encryption API.
https://learn.microsoft.com/en-us/windows/win32/seccng/encrypting-data-with-cng

And I found four questions that confused me.

Q1: If I execute the link code in application A three times, each time I save the key generated by BcryptExportkey as a static variable, I can decrypt the newly encrypted data with any of the three keys, is that right?

Q2: If I execute the link code in application A and B respectively, and pass the key generated by A to B, B can also use the key to decrypt, is that right?

Q3: Will the key generated by BcryptExportkey API be different in different Windows' versions?

Q4: The key generated by BcryptExportkey are the same, so what parameters do AES-GCM mode use to complete the decryption?

Sorry, I'm still a rookie. so many questions here. I hope you can guide me.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,429 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,543 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 11,501 Reputation points Microsoft Vendor
    2021-06-18T08:28:22.707+00:00

    Q4: The algorithm described by AES is a symmetric-key algorithm, meaning the same key is used for both encrypting and decrypting the data.
    CipherText + Key ==> PlainText.
    PlainText + Key ==> CipherText.
    Searching for more details about AES Algorithm.

    Q1 Yes
    Q2 Yes
    The Sample uses same key and same algorithm(AES) to export. So the exported key can be used exchanged.
    Q3: According to BCryptGenerateSymmetricKey function, The BCryptGenerateSymmetricKey function creates a key object for use with a symmetrical key encryption algorithm from a supplied key. There is no other information involved.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful