Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winapi 在win 7下使用命名密钥容器更改密码混乱_Winapi_Cryptoapi - Fatal编程技术网

Winapi 在win 7下使用命名密钥容器更改密码混乱

Winapi 在win 7下使用命名密钥容器更改密码混乱,winapi,cryptoapi,Winapi,Cryptoapi,在一些运行Windows7的系统上,我们在一个 如果我们在调用时更改用户的密码,则命名密钥容器 CryptAcquireCertificatePrivateKey()我们得到一个错误 CRYPT_E_NO_KEY_属性(0x8009200B) 并不是所有的盒子都是这样。我们最初认为这是一个不在网络上的域机器的东西,它不能刷新它的域内容,但我们让它在一些独立的机器上复制 我读钥匙的密码 if((StoreHandle = CertOpenStore(CERT_STORE_PROV_SYSTEM,

在一些运行Windows7的系统上,我们在一个 如果我们在调用时更改用户的密码,则命名密钥容器 CryptAcquireCertificatePrivateKey()我们得到一个错误 CRYPT_E_NO_KEY_属性(0x8009200B)

并不是所有的盒子都是这样。我们最初认为这是一个不在网络上的域机器的东西,它不能刷新它的域内容,但我们让它在一些独立的机器上复制

我读钥匙的密码

if((StoreHandle = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, QWARQ_CERT_STORE_NAME)) != NULL)
     {
        /* Look for certificate with matching user guid.            */
        if((CertContext = CertFindCertificateInStore(StoreHandle,PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, 0, CERT_FIND_SUBJECT_STR,DataBuffer, NULL)) != NULL)
        {
           if(CryptAcquireCertificatePrivateKey(CertContext, 0,NULL, &CryptProvHandle, &KeySpec, &FreeHandle))
           {
           }
           else
           {
                   DWORD dwError=GetLastError();   //CRYPT_E_NO_KEY_PROPERTY
           }
        }
     }
下面是生成密钥/密钥容器的代码

if(CryptAcquireContext(&hCryptProv,KEY_CONTAINER_NAME, NULL,PROV_RSA_FULL, 0) == FALSE) //CRYPT_NEWKEYSET
{
    DWORD result = GetLastError();
    if (NTE_BAD_KEY_STATE  == result)
    {
        DebugLogging::DbgPrintF(TEXT("[CertInitialization] NTE_BAD_KEY_STATE - user has changed his password \n"), result);
        return false;
    }
    else if (NTE_BAD_KEYSET != result)
    {
        DebugLogging::DbgPrintF(TEXT("[CertInitialization] could not acquire CSP[0x%x]\n"), result);
        return false;
    }

    if(CryptAcquireContext(&hCryptProv, KEY_CONTAINER_NAME, NULL,PROV_RSA_FULL, CRYPT_NEWKEYSET) == FALSE) //CRYPT_NEWKEYSET
    {
        DWORD result = GetLastError();
        DebugLogging::DbgPrintF(TEXT("[CertInitialization] could not acquire CSP from new keyset[0x%x]\n"), result);
        return false;
    }
}
if(CryptGenKey(hCryptProv, AT_KEYEXCHANGE, RSA2048BIT_KEY |CRYPT_EXPORTABLE, &hKey)== FALSE)
{
    DebugLogging::DbgPrintF(TEXT("CertGeneration() could not generate key[%d]\n"),GetLastError());
    return false;
} 

在了解更多关于DPAPI的信息之后

密码更改

在这种方法中,在密码更改期间可以连续访问用户的主密钥。在Active Directory域中的密码更改操作期间,Winlogon组件将调用DPAPI:

* DPAPI receives notification from Winlogon during a password change operation.
* DPAPI decrypts all master keys that were encrypted with the user's old passwords.
* DPAPI re-encrypts all master keys with the user's new password.
密码重置(设置)


在此方法中,管理员强制重置用户密码。密码重置比密码更改更复杂。由于管理员未以用户身份登录,并且无权访问用户的旧密码,因此该旧密码不能用于解密旧主密钥并使用新密码对其重新加密

了解有关DPAPI的更多信息后

密码更改

在这种方法中,在密码更改期间可以连续访问用户的主密钥。在Active Directory域中的密码更改操作期间,Winlogon组件将调用DPAPI:

* DPAPI receives notification from Winlogon during a password change operation.
* DPAPI decrypts all master keys that were encrypted with the user's old passwords.
* DPAPI re-encrypts all master keys with the user's new password.
密码重置(设置)


在此方法中,管理员强制重置用户密码。密码重置比密码更改更复杂。由于管理员未以用户身份登录,并且无权访问用户的旧密码,因此该旧密码不能用于解密旧主密钥并使用新密码对其重新加密

DPAPI还存储主密钥的备份副本,并使用域控制器提供的公钥对其进行加密。当主密钥解密失败时,windows要求域控制器使用DC的私钥知识对备份副本进行解密。请参阅DPAPI还存储主密钥的备份副本,并使用域控制器提供的公钥对其进行加密。当主密钥解密失败时,windows要求域控制器使用DC的私钥知识对备份副本进行解密。看见