Error 0 During Cryptdecrypt
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
Cryptdecrypt Nte_bad_data
about Stack Overflow the company Business Learn more about hiring developers or posting ads cryptdecrypt bad data with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow cryptencrypt example c++ is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why does my CryptDecrypt fail with error code 0x80090005 (NTE_BAD_DATA)? up vote
Cryptencrypt Msdn
3 down vote favorite I wrote this piece of code to decrypt a given cipher using a given key and iv. It works fine until CryptDecrypt which returns false and GetLastError() returns 0x80090005 (which should be NTE_BAD_DATA). #include
Cryptderivekey Msdn
} }; void AesDecrypt(unsigned char *output, unsigned char *input, int inLen, unsigned char *key, unsigned char *iv, int &plainSize) { HCRYPTPROV provider; AesKey rawKey; HCRYPTKEY cKey; BOOL hr = CryptAcquireContext(&provider, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, 0); if (hr == FALSE) throw "Unable to acquire AES Context"; for (int i = 0; i < 16; i++) rawKey.cbKey[i] = key[i]; hr = CryptImportKey(provider, (BYTE *) &rawKey, sizeof(AesKey), NULL, 0, &cKey); if (hr == FALSE) throw "Unable to import given key"; hr = CryptSetKeyParam(cKey, KP_IV, (BYTE *) iv, 0); if (hr == FALSE) throw "Unable to set IV"; DWORD dwMode = CRYPT_MODE_CBC; hr = CryptSetKeyParam(cKey, KP_MODE, (BYTE*) &dwMode, 0); if (hr == FALSE) throw "Unable to set mode"; memcpy(output, input, inLen); DWORD d = (DWORD) inLen; hr = CryptDecrypt(cKey, NULL, TRUE, 0, output, &d); if (hr == FALSE) { int err = GetLastError(); throw "Error during Decryption"; } plainSize = d; } If you have any idea, please share :) Thanks in advance... c++ windows cryptoapi share|improve this question asked Nov 25 '11 at 8:49 AlfaOmega08 6131028 3 Unrelated to your problem, but you should not make it a habit to ZeroMemory(this). While it might work in a simple structure with only integer data, floating point numbers in the c
here for a quick overview of the site Help Center Detailed answers to any questions msdn cryptimportkey you might have Meta Discuss the workings and policies of
Cryptgetkeyparam
this site About Us Learn more about Stack Overflow the company Business Learn more about hiring cryptcreatehash developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a http://stackoverflow.com/questions/8266581/why-does-my-cryptdecrypt-fail-with-error-code-0x80090005-nte-bad-data community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bad Data error at CryptDecrypt when using AES 256 (MS CryptoAPI) up vote 1 down vote favorite I'm trying to decrypt - using the microsoft's CryptoAPI in C++ - a short message encrypted http://stackoverflow.com/questions/7851402/bad-data-error-at-cryptdecrypt-when-using-aes-256-ms-cryptoapi using mcrypt_encrypt in PHP. The php line is: mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $key, $msg, MCRYPT_MODE_CBC); where $key and $msg are strings. In C++ I have the key, and my decryption function looks like this: bool decrypt( const unsigned char* input_buffer, const size_t& input_size, const unsigned char* key, const size_t& key_size, unsigned char* output_buffer, DWORD* out_size) { Log(L"START init_crypto"); bool ret = false; HCRYPTKEY hKey = NULL; HCRYPTPROV hCryptProv = NULL; DWORD dwDataLen = 0; // Attempt to acquire a handle to the crypto provider for AES if(0 == CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT) ){//PROV_RSA_AES Log(L"CryptAcquireContext failed with code %ld", GetLastError()); goto end; } // key creation based on // http://mirror.leaseweb.com/NetBSD/NetBSD-release-5-0/src/dist/wpa/src/crypto/crypto_cryptoapi.c struct { BLOBHEADER hdr; DWORD len; BYTE key[32]; } key_blob; key_blob.hdr.bType = PLAINTEXTKEYBLOB; key_blob.hdr.bVersion = CUR_BLOB_VERSION; key_blob.hdr.reserved = 0; key_blob.hdr.aiKeyAlg = CALG_AES_256; key_blob.len = 32;//key_size; memset(key_blob.key, '\0', sizeof(key_blob.key)); assert(key_size <= sizeof(key_blob.key)); CopyMemory(key_blob.key, key, min(key_size, sizeof(key_blob.key))); if (!CryptImportKey( hCryptProv, (BYTE *)&key_blob, sizeof(key_blob), 0, CRYPT_EXPORTABLE, &hKey)){ Log(L"Error in CryptImportKey 0x%08x \
spent hours looking for a solution to this error and finally I found one. Now my PC is much faster and more importantly I http://repairpcfan.com/error-0-during-cryptdecrypt.php have stopped seeing this error! Follow the steps below to cure this problem. http://www.cplusplus.com/forum/windows/27642/ Click here to get the free tool. Click 'Start Scan' to scan your PC for errors If errors are found, click 'Next' then 'Fix Now' to fix the problem You may need to reboot your PC for the changes to take effect. After scanning my PC using RegCure, I can confirm that Error error 0 0 During Cryptdecrypt did not return. My PC is now running much faster and is far more reliable. If you have any comments or questions, please feel free to submit a message using the form below. How Did I Get This Error? Most errors on your machine are caused by uninstalling programs, installing new ones and accidentally deleting important files. It's important to scan your error 0 during PC every now and again to ensure that these files are in place and everything is as it should be. Visitor Comments 8 Comments for "Want to Fix Error 0 During Cryptdecrypt?" Theresia - Today “This fixed the Error 0 During Cryptdecrypt message. I can't believe it, Thank you!!!” Timmy- Yesterday “I spent all day trying to sort this out then found your site. Seems to have fixed it, thanks x” Micki- 1 Month Ago “You are an absolute legend! Worked a treat!” France- 1 Month Ago “Thanks for sharing, I no longer have to put up with the dreaded Error 0 During Cryptdecrypt” Sherika- 2 Months Ago “Will this work with Windows Vista?” Londa- 6 Months Ago “Thank you so much for this. I thought my PC had died when I got this error but now it's as good as new. I owe you a drink!” :Henry B: - 7 Months Ago “I was getting loads of errors until I tried this. All sorted now. Thanks for the info.” Your Name Your Email Comment Error 0 During Cryptdecrypt With the max on each on my opinion Exclusive on the maker said their sp
again when ever the user wants to decrypt the file back again. The problem or root problem may be that when the session key is exported the key's length may be incorrect, and is probably causing the decrypted text to be truncated. Can someone please help me, and I'll post the code below. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
if (LOWORD(wParam) == WORD(decrypt_id)) { wchar_t filepath[256]; GetWindowTextW(hWnd, filepath, (int)256); _wstat(filepath, &info4); const long bytesize = info4.st_size; unsigned char *buffer = new unsigned char[bytesize]; file = _wfopen(filepath, L"r"); size_t readsize = fread(buffer, sizeof(char), info4.st_size , file); BOOL returnn = CryptAcquireContext(&hCryptProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, 0); wchar_t current_username_buffer[256]; DWORD size2 = 32767; wchar_t dest2[256] = L"C:\\Users\\"; GetUserName(current_username_buffer, &size2); wcscat_s(dest2, current_username_buffer); wchar_t src[256] = L"\\Desktop\\"; wcscat_s(dest2, src); wchar_t filepath2[] = L"encryptkey.bin"; wcscat_s(dest2, filepath2); _wstat(dest2, &info5); BYTE readkey[140]; file4 = _wfopen(dest2, L"rb"); long lsize = ftell(file4); size_t readsize2 = fread(readkey, sizeof(char), info5.st_size, file4); BOOL rvalue1 = CryptImportKey(hCryptProv, readkey, sizeof(readkey), 0, 0, &hkey); DWORD dataleng