本文整理汇总了C++中CryptDecrypt函数的典型用法代码示例。如果您正苦于以下问题:C++ CryptDecrypt函数的具体用法?C++ CryptDecrypt怎么用?C++ CryptDecrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CryptDecrypt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xmlSecMSCryptoKWAesBlockDecrypt
static int
xmlSecMSCryptoKWAesBlockDecrypt(const xmlSecByte * in, xmlSecSize inSize,
xmlSecByte * out, xmlSecSize outSize,
void * context) {
xmlSecMSCryptoKWAesCtxPtr ctx = (xmlSecMSCryptoKWAesCtxPtr)context;
HCRYPTKEY cryptKey = 0;
DWORD dwCLen;
xmlSecAssert2(in != NULL, -1);
xmlSecAssert2(inSize >= XMLSEC_KW_AES_BLOCK_SIZE, -1);
xmlSecAssert2(out != NULL, -1);
xmlSecAssert2(outSize >= inSize, -1);
xmlSecAssert2(ctx != NULL, -1);
xmlSecAssert2(ctx->pubPrivKey != 0, -1);
xmlSecAssert2(xmlSecBufferGetSize(&ctx->keyBuffer) == ctx->keySize, -1);
/* Import this key and get an HCRYPTKEY handle, we do it again and again
to ensure we don't go into CBC mode */
if (!xmlSecMSCryptoImportPlainSessionBlob(ctx->cryptProvider,
ctx->pubPrivKey,
ctx->algorithmIdentifier,
xmlSecBufferGetData(&ctx->keyBuffer),
xmlSecBufferGetSize(&ctx->keyBuffer),
TRUE,
&cryptKey)) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"xmlSecMSCryptoImportPlainSessionBlob",
XMLSEC_ERRORS_R_XMLSEC_FAILED,
XMLSEC_ERRORS_NO_MESSAGE);
return(-1);
}
xmlSecAssert2(cryptKey != 0, -1);
/* Set process last block to false, since we handle padding ourselves, and MSCrypto padding
* can be skipped. I hope this will work .... */
if(out != in) {
memcpy(out, in, inSize);
}
dwCLen = inSize;
if(!CryptDecrypt(cryptKey, 0, FALSE, 0, out, &dwCLen)) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"CryptEncrypt",
XMLSEC_ERRORS_R_CRYPTO_FAILED,
XMLSEC_ERRORS_NO_MESSAGE);
CryptDestroyKey(cryptKey);
return(-1);
}
/* cleanup */
CryptDestroyKey(cryptKey);
return(dwCLen);
}
示例2: DecryptData
bool CEncryptSyncData::DecryptData(unsigned char * pchrSrcBuf,DWORD nLen)
{
if(!CryptDecrypt(hKey,0,TRUE,0,(BYTE *)pchrSrcBuf,&nLen))
{
return false;
}
else
{
return true;
}
}
示例3: decode
static DWORD
decode( DWORD length, BYTE *buffer, DWORD bufsiz )
{
if ( ! CryptDecrypt( sessKey, 0, TRUE, 0, buffer, &length ) )
{
fprintf( stderr, "CryptDecrypt() failed: 0x%x\n", GetLastError() );
return( 0 );
}
return( length );
}
示例4: rsautil_decryptFileWithKey
void rsautil_decryptFileWithKey(HCRYPTPROV hProv, HCRYPTKEY hUserRsaKey, HCRYPTKEY hFreeRsaKey, LPWSTR filename)
{
HCRYPTKEY hUserFileAesKey;
PWANA_FORMAT pbEncData;
PWCHAR p;
DWORD cbEncData, cbRealDataLen, cryptoMode = CRYPT_MODE_CBC;
kprintf(L"File %s -- ", filename);
if(kull_m_file_readData(filename, (PBYTE *) &pbEncData, &cbEncData))
{
if(p = wcsrchr(filename, L'.'))
{
*p = L'\0'; // 'delete' the WNCRY extension
if(pbEncData->magic == WANA_MAGIC)
{
if(CryptDecrypt(hUserRsaKey, 0, TRUE, 0, pbEncData->key, &pbEncData->enc_keysize) || (hFreeRsaKey ? CryptDecrypt(hFreeRsaKey, 0, TRUE, 0, pbEncData->key, &pbEncData->enc_keysize) : FALSE)) // decrypt the raw AES key from your RSA key (from userone of free if present)
{
if(SIMPLE_kull_m_crypto_hkey(hProv, CALG_AES_128, pbEncData->key, pbEncData->enc_keysize, 0, &hUserFileAesKey)) // let's make a AES 128 Windows key from raw bytes
{
if(CryptSetKeyParam(hUserFileAesKey, KP_MODE, (PBYTE) &cryptoMode, 0)) // we'll do CBC
{
cbRealDataLen = cbEncData - FIELD_OFFSET(WANA_FORMAT, data);
if(CryptDecrypt(hUserFileAesKey, 0, FALSE, 0, pbEncData->data, &cbRealDataLen)) // decrypt final data (padding issue, so 'FALSE' arg)
{
if(kull_m_file_writeData(filename, pbEncData->data, (ULONG) pbEncData->qwDataSize))
kprintf(L"OK\n");
else PRINT_ERROR_AUTO(L"kull_m_file_writeData");
}
else PRINT_ERROR_AUTO(L"CryptDecrypt(AES)");
}
CryptDestroyKey(hUserFileAesKey);
}
}
else PRINT_ERROR_AUTO(L"CryptDecrypt(RSA)");
}
else PRINT_ERROR(L"ERROR: WANACRY! magic number not found\n");
}
else PRINT_ERROR(L"ERROR: no \'.\' at the end of the user file ?\n");
LocalFree(pbEncData);
}
else PRINT_ERROR_AUTO(L"kull_m_file_readData");
}
示例5: des3_encrypt_blk
void des3_encrypt_blk(unsigned char *blk, int len) {
DWORD dlen;
dlen = len;
if(CryptEncrypt(hDESKey[0][0], 0, FALSE, 0, blk, &dlen, len + 8) == 0)
fatalbox("Error encrypting block!\n");
if(CryptDecrypt(hDESKey[0][1], 0, FALSE, 0, blk, &dlen) == 0)
fatalbox("Error encrypting block!\n");
if(CryptEncrypt(hDESKey[0][2], 0, FALSE, 0, blk, &dlen, len + 8) == 0)
fatalbox("Error encrypting block!\n");
}
示例6: DWORD
std::string CStringUtils::Decrypt(const std::string& s, const std::string& password)
{
std::string decryptstring;
HCRYPTPROV hProv = NULL;
// Get handle to user default provider.
if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
{
HCRYPTHASH hHash = NULL;
// Create hash object.
if (CryptCreateHash(hProv, CALG_SHA_512, 0, 0, &hHash))
{
// Hash password string.
DWORD dwLength = DWORD(sizeof(WCHAR)*password.size());
if (CryptHashData(hHash, (BYTE *)password.c_str(), dwLength, 0))
{
HCRYPTKEY hKey = NULL;
// Create block cipher session key based on hash of the password.
if (CryptDeriveKey(hProv, CALG_AES_256, hHash, CRYPT_EXPORTABLE, &hKey))
{
dwLength = DWORD(s.size() + 1024); // 1024 bytes should be enough for padding
std::unique_ptr<BYTE[]> buffer(new BYTE[dwLength]);
std::unique_ptr<BYTE[]> strIn(new BYTE[s.size() + 1]);
if (buffer && strIn)
{
if (CStringUtils::FromHexString(s, strIn.get()))
{
// copy encrypted password to temporary buffer
memcpy(buffer.get(), strIn.get(), s.size());
dwLength = DWORD(s.size() / 2);
CryptDecrypt(hKey, 0, true, 0, (BYTE *)buffer.get(), &dwLength);
decryptstring = std::string((char*)buffer.get(), dwLength);
if (!decryptstring.empty() && (decryptstring[0] == '*'))
{
decryptstring = decryptstring.substr(1);
}
else
decryptstring.clear();
}
}
CryptDestroyKey(hKey); // Release provider handle.
}
}
CryptDestroyHash(hHash); // Destroy session key.
}
CryptReleaseContext(hProv, 0);
}
else
DebugBreak();
return decryptstring;
}
示例7: QByteArray
QByteArray QCSP::decrypt( const QByteArray &data )
{
HCRYPTKEY key = 0;
if( !CryptGetUserKey( d->h, AT_KEYEXCHANGE, &key ) )
return QByteArray();
QByteArray rev = reverse( data );
DWORD size = rev.size();
bool result = CryptDecrypt( key, 0, true, 0, LPBYTE(rev.data()), &size );
CryptDestroyKey( key );
return result ? rev : QByteArray();
}
示例8: TOE
void
CryptoProxy::decrypt(CryptoKey* key, const ByteVector& data, ByteVector& decryptedData)
{
decryptedData = data; //Crypto decrypts in-place
DWORD dataSize = static_cast<DWORD>(data.size());
// NOTE: check FINAL again - currently no FINAL to avoid checking padding
//TOE(CryptDecrypt(*key, 0, TRUE, 0/*flags*/, &decryptedData.front(), &dataSize), "CryptDecrypt");
TOE(CryptDecrypt(*key, 0, FALSE, 0/*flags*/, &decryptedData.front(), &dataSize), "CryptDecrypt");
if (dataSize < decryptedData.size())
{
decryptedData.resize(decryptedData.size() - dataSize);
}
}
示例9: aes_decrypt
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
{
struct aes_context *akey = ctx;
DWORD dlen;
os_memcpy(plain, crypt, 16);
dlen = 16;
if (!CryptDecrypt(akey->ckey, 0, FALSE, 0, plain, &dlen)) {
wpa_printf(MSG_DEBUG, "CryptoAPI: CryptDecrypt failed: %d",
(int) GetLastError());
}
}
示例10: capi_rsa_priv_dec
int capi_rsa_priv_dec(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
int i;
unsigned char *tmpbuf;
CAPI_KEY *capi_key;
CAPI_CTX *ctx;
ctx = ENGINE_get_ex_data(rsa->engine, capi_idx);
CAPI_trace(ctx, "Called capi_rsa_priv_dec()\n");
capi_key = RSA_get_ex_data(rsa, rsa_capi_idx);
if (!capi_key)
{
CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_CANT_GET_KEY);
return -1;
}
if(padding != RSA_PKCS1_PADDING)
{
char errstr[10];
BIO_snprintf(errstr, 10, "%d", padding);
CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_UNSUPPORTED_PADDING);
ERR_add_error_data(2, "padding=", errstr);
return -1;
}
/* Create temp reverse order version of input */
if(!(tmpbuf = OPENSSL_malloc(flen)) )
{
CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, ERR_R_MALLOC_FAILURE);
return -1;
}
for(i = 0; i < flen; i++)
tmpbuf[flen - i - 1] = from[i];
/* Finally decrypt it */
if(!CryptDecrypt(capi_key->key, 0, TRUE, 0, tmpbuf, &flen))
{
CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_DECRYPT_ERROR);
capi_addlasterror();
OPENSSL_free(tmpbuf);
return -1;
}
else memcpy(to, tmpbuf, flen);
OPENSSL_free(tmpbuf);
return flen;
}
示例11: DecodingFile
void DecodingFile(QString fPath, HCRYPTKEY hKey)
{
QFile myFile(fPath);
QString fName = myFile.fileName();
QRegExp rx("[^eFile.dat]");
int typeLen = 0;
rx.indexIn(fName, typeLen);
QFile srcFile("1" + fName.mid(0, typeLen));
DWORD blockLen = 0, fDataSize;
BYTE* fData;
myFile.open(QIODevice::ReadOnly);
if (!myFile.exists())
{
QMessageBox::critical(0, "Ошибка", "Файл не выбран", QMessageBox::Ok);
return;
}
srcFile.open(QIODevice::WriteOnly);
CryptDecrypt(hKey, 0, true, 0, NULL, &blockLen);
fData = new BYTE[blockLen];
memset(fData, 0, blockLen);
while ((fDataSize = myFile.read((char*) fData, blockLen)))
{
if (!CryptDecrypt(hKey, 0, fDataSize < blockLen, 0, fData, &fDataSize))
{
QMessageBox::critical(0, "Ошибка", "Шифрование данных. " + GetErrorString(GetLastError()),
QMessageBox::Ok);
return;
}
srcFile.write((char*)fData, fDataSize);
memset(fData, 0, blockLen);
}
delete[] fData;
myFile.close();
srcFile.close();
}
示例12: UnprotectData
void UnprotectData(const std::vector<unsigned char>& prot, secure_buffer& data)
{
// populate buffer with encrypted data
secure_buffer buf(prot.begin(), prot.end());
// set initial size
DWORD dwBufferSize = buf.size();
// decrypt data using session key
if (!CryptDecrypt(SessionKey::Instance(), 0, TRUE, 0, &buf[0], &dwBufferSize))
throw SystemError(GetLastError());
// set actual data size
buf.resize(dwBufferSize);
// set result
data.swap(buf);
}
示例13: TEXT
bool Encryption::Decrypt(TCHAR * file)
{
pszSourceFile = file;
pszDestinationFile = TEXT("temp");
OpenFile();
ReadFileType();
if(bIsPlaintext)
{
if(hSourceFile)
CloseHandle(hSourceFile);
if(hDestinationFile)
CloseHandle(hDestinationFile);
DeleteFile(pszDestinationFile);
return true;
}
DWORD dwCount;
PBYTE pbBuffer = NULL;
DWORD dwBlockLen;
dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
if(!(pbBuffer = (PBYTE)malloc(dwBlockLen)))
return false;
bool fEOF = false;
do
{
if(!ReadFile(hSourceFile, pbBuffer, dwBlockLen, &dwCount, NULL))
return false;
if(dwCount < dwBlockLen)
fEOF = true;
if(!CryptDecrypt(hKey, 0, fEOF, 0, pbBuffer, &dwCount))
return false;
if(!WriteFile(hDestinationFile, pbBuffer, dwCount, &dwCount, NULL))
return false;
} while(!fEOF);
if(hSourceFile)
CloseHandle(hSourceFile);
if(hDestinationFile)
CloseHandle(hDestinationFile);
if(!ReplaceFile(pszSourceFile, pszDestinationFile, NULL, REPLACEFILE_WRITE_THROUGH, 0, 0))
return false;
return true;
}
示例14: crypto_cipher_decrypt
int crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt,
u8 *plain, size_t len)
{
DWORD dlen;
os_memcpy(plain, crypt, len);
dlen = len;
if (!CryptDecrypt(ctx->key, 0, FALSE, 0, plain, &dlen)) {
cryptoapi_report_error("CryptDecrypt");
return -1;
}
return 0;
}
示例15: exsltCryptoCryptoApiRc4Decrypt
static void
exsltCryptoCryptoApiRc4Decrypt (xmlXPathParserContextPtr ctxt,
const unsigned char *key,
const unsigned char *msg, int msglen,
unsigned char *dest, int destlen) {
HCRYPTPROV hCryptProv;
HCRYPTKEY hKey;
HCRYPTHASH hHash;
DWORD dwDataLen;
unsigned char hash[HASH_DIGEST_LENGTH];
if (msglen > destlen) {
xsltTransformError (xsltXPathGetTransformContext (ctxt), NULL,
NULL,
"exslt:crypto : internal error exsltCryptoCryptoApiRc4Encrypt dest buffer too small.\n");
return;
}
if (!CryptAcquireContext (&hCryptProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
exsltCryptoCryptoApiReportError (ctxt, __LINE__);
return;
}
hHash = exsltCryptoCryptoApiCreateHash (ctxt, hCryptProv,
CALG_SHA1, key,
RC4_KEY_LENGTH, hash,
HASH_DIGEST_LENGTH);
if (!CryptDeriveKey
(hCryptProv, CALG_RC4, hHash, 0x00800000, &hKey)) {
exsltCryptoCryptoApiReportError (ctxt, __LINE__);
goto fail;
}
/* Now encrypt data. */
dwDataLen = msglen;
memcpy (dest, msg, msglen);
if (!CryptDecrypt (hKey, 0, TRUE, 0, dest, &dwDataLen)) {
exsltCryptoCryptoApiReportError (ctxt, __LINE__);
goto fail;
}
fail:
if (0 != hHash) {
CryptDestroyHash (hHash);
}
CryptDestroyKey (hKey);
CryptReleaseContext (hCryptProv, 0);
}