cryptoapi

TLS 1.2 - The token supplied to the function is invalid

≡放荡痞女 提交于 2021-01-28 19:26:44
问题 I have this strange problem, SslStream.AuthenticateAsClient() throws following exception: System.Security.Authentication.AuthenticationException : A call to SSPI failed, see inner exception. ----> System.ComponentModel.Win32Exception : The token supplied to the function is invalid It happens only when Tls12 is required by the client: SslStream.AuthenticateAsClient(..., ..., SslProtocols.Tls12); Code works properly for Ssl3, Tls11 and Tls. Server certificate is self-signed and 'old'. It uses

How to export EC private key as PKCS#1 or PKCS#8 format from certificate store by CNG?

二次信任 提交于 2020-04-18 05:47:56
问题 I tried to export private key from certificate store by CNG API. It work fine when export RSA private key, but failed in EC private key. The code failed in NCryptExportKey() with 0x80090029 . Is there any document from MS said: Export EC private key not support? or any sample code? Here is my code: NCRYPT_KEY_HANDLE hKey = NULL; SECURITY_STATUS secStatus = ERROR_SUCCESS; NTSTATUS status = STATUS_UNSUCCESSFUL; DWORD dwKeySpec, cbData = 0, cbBlob = 0, KeyPolicy = 0; PBYTE pbHash = NULL, pbBlob

Pinvoking adwapi.dll - cryptDecrypt and cryptEncrypt functions, weird problem

旧街凉风 提交于 2020-01-25 07:23:06
问题 I am observing wierd behaviour of this function, the string that I want to encrypt contains 14 bytes, if I use the function to send lenght of buffer = 14, it fails ("an internal error" - very descriptive and most helpful error code), but it works when the buffer length (and the buffer itself) is 128 bytes large. I overcame this problem by making a size 128 byte array and I copied the 14 bytes from the plain text (that I wish to encrypt), When I decrypt those bytes, I must once again give the

How can I import an RSA public key from either XML or modulus/exponent in native code for use with Windows CAPI's CryptVerifySignature?

北慕城南 提交于 2020-01-14 05:29:06
问题 In C#, I am able to validate a hash against a public key in either of the following ways: // Import from raw modulus and exponent using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { RSAParameters rsaKeyInfo = new RSAParameters {Modulus = modulus, Exponent = exponent}; rsa.ImportParameters(rsaKeyInfo); return rsa.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA512"), signature); } // Import from XML using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa

How can I import an RSA public key from either XML or modulus/exponent in native code for use with Windows CAPI's CryptVerifySignature?

让人想犯罪 __ 提交于 2020-01-14 05:29:06
问题 In C#, I am able to validate a hash against a public key in either of the following ways: // Import from raw modulus and exponent using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { RSAParameters rsaKeyInfo = new RSAParameters {Modulus = modulus, Exponent = exponent}; rsa.ImportParameters(rsaKeyInfo); return rsa.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA512"), signature); } // Import from XML using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { rsa

How to AES CBC encryption Using cryptoAPI

爱⌒轻易说出口 提交于 2020-01-03 06:06:37
问题 I want to encrypt a file with AES CBC mode encryption, Using cryptoAPI functions and set my own key from the command-line (It my change in the code) I imagine that the key (after change) will be 1a1dc91c907325c6 and tried in this form: HCRYPTPROV hProv = NULL; HCRYPTKEY hKey = NULL; DWORD dwBlobLen; PBYTE pbKeyBlob = NULL; pbKeyBlob = (PBYTE)"1a1dc91c907325c6"; if(!CryptAcquireContext(&hProv, NULL,NULL, PROV_RSA_AES,CRYPT_VERIFYCONTEXT)) { printf(" Error in AcquireContext 0x%08x \n"

Hard coded AES-256 key with WinCrypt & CryptImportKey

允我心安 提交于 2020-01-02 07:25:13
问题 I need to have a Win32 application load a hard coded AES-256 key, ideally using the WinCrypt.h methods. I've got my key in an unsigned char[32] but I can't find the correct format of a key blob to pass to CryptImportKey. Everything seems to give me invalid parameter errors. Is there any way to do this? (Also important is how to set IV in WinCrypt. I can't see how to do that at all) 回答1: Solved it. I was using the wrong bType and using 256 for keySize instead of 32. BYTE myPrivateKey[] = {1,2

Associate private key to certificate for PFXExportCertStoreEx

拥有回忆 提交于 2020-01-01 16:54:11
问题 I'm trying to export certificate to pfx file. Here's what I do (simplified): h = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, CERT_STORE_CREATE_NEW_FLAG, NULL); p = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, CertBlob.pbData, CertBlob.cbData); CertSetCertificateContextProperty(p, CERT_KEY_PROV_HANDLE_PROP_ID, 0, &hPrivKey); CertAddCertificateContextToStore(h, p, CERT_STORE_ADD_ALWAYS, NULL); PFXExportCertStoreEx(h, &SomeBlob, L"", NULL, EXPORT_PRIVATE_KEYS); PFX

Random numbers for Windows Phone 8 and Windows Store 8?

时光怂恿深爱的人放手 提交于 2019-12-31 07:04:21
问题 I'm struggling with a port of a couple of security libraries to the Windows Phone 8 and Windows Store 8 platform. I need a function which provides random numbers. Win32 has CryptGenRandom and even RtlGenRandom . Windows Store 10 and Universal Windows has BCryptGenRandom . However, there's a hole for Windows Phone 8 and Windows Store 8 because CryptoAPI is not available, and CNG is only available on Windows 10 and Universal Windows. The MSDN docs say BCryptGenRandom is available for "Windows

Random numbers for Windows Phone 8 and Windows Store 8?

☆樱花仙子☆ 提交于 2019-12-31 07:04:20
问题 I'm struggling with a port of a couple of security libraries to the Windows Phone 8 and Windows Store 8 platform. I need a function which provides random numbers. Win32 has CryptGenRandom and even RtlGenRandom . Windows Store 10 and Universal Windows has BCryptGenRandom . However, there's a hole for Windows Phone 8 and Windows Store 8 because CryptoAPI is not available, and CNG is only available on Windows 10 and Universal Windows. The MSDN docs say BCryptGenRandom is available for "Windows