S
S
shushlyakov2015-07-15 21:57:41
Cryptography
shushlyakov, 2015-07-15 21:57:41

How to decrypt XML GOST 28147-89 via CryptoPro\VipNet?

CryptoPro and VipNet provide libraries that implement the MS CryptoAPI interface.
There is XML, it contains the encryption algorithm urn:ietf:params:xml:ns:cpxmlsec:algorithms:gost28147
and the key agreement algorithm urn:ietf:params:xml:ns:cpxmlsec:algorithms:transport-gost2001 The
session key seems to have been parsed / import:.

// Получение дескриптора криптопровайдера
CryptAcquireContext(&hProv, __CONTAINER_NAME__,NULL,PROV_GOST_2001_DH,0);
// Получение дескриптора закрытого ключа получателя.
CryptGetUserKey(hProv, AT_KEYEXCHANGE, &hKey);
// Получение ключа согласования импортом эфемерального ключа отправителя
// на открытом ключе получателя.
CryptImportKey(hProv, bEphemeralPublicKeySimple, 100, hKey, 0, &hAgreeKey);
// Установление алгоритма ключа согласования
ALG_ID alg = CALG_SIMPLE_EXPORT; // алгоритм ключа согласования
CryptSetKeyParam(hAgreeKey, KP_ALGID, (LPBYTE)&alg, 0);
// Получение сессионного ключа импортом зашифрованного сессионного ключа
// на ключе Agree.
CryptImportKey(hProv,pbKeyBlobSimple,dwBlobLenSimple,hAgreeKey,0,&hSessionKey);

The problem is in the decryption itself:
CryptDecrypt(hSessionKey, 0, bFinal, 0, pbContent, &cbContent);

The function works without errors, but the result is not even close to the original message.
Has anyone experienced this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question