Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.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
MS office的解密_C_Linux_Encryption_Cryptography_Ms Office - Fatal编程技术网

MS office的解密

MS office的解密,c,linux,encryption,cryptography,ms-office,C,Linux,Encryption,Cryptography,Ms Office,我正在解密加密的MS Excel(RC4 encryption with SHA1),密码是已知的。在vs2010中,我可以正确解密它,但是,我的程序必须在Win和linux下工作。我现在不知道如何在linux下获得加密密钥,这与Win下的类似: int getEncrypKey(HCRYPTKEY *hKey, int blocknum) { //------------------------H0 = H(salt, password)----- BYTE *pbSaltan

我正在解密加密的MS Excel(RC4 encryption with SHA1),密码是已知的。在vs2010中,我可以正确解密它,但是,我的程序必须在Win和linux下工作。我现在不知道如何在linux下获得加密密钥,这与Win下的类似:

int getEncrypKey(HCRYPTKEY *hKey, int blocknum)
{
    //------------------------H0 = H(salt, password)-----
    BYTE *pbSaltandPwdHash = NULL;
    DWORD dwSaltandPwdLen = 0;

    pbSaltandPwdHash = SHA1_2(psalt, 16, ppwd, strlen(pwd)/2, &dwSaltandPwdLen);
    printf("SHA1 of SaltandPwd:\n");
    for(DWORD i = 0 ; i < dwSaltandPwdLen ; i++) {
    printf("%2.2x ",pbSaltandPwdHash[i]);
    }
    printf("\n");
    //------------------------H0 = H(salt, password)-----

    //------------------------Hfinal = H(H0, block)-----
    HCRYPTHASH hHash1 = 0;

    CryptCreateHash( hCryptProv, CALG_SHA1, 0, 0, &hHash1) ;
    CryptHashData( hHash1, pbSaltandPwdHash, dwSaltandPwdLen, 0) ;
    CryptHashData( hHash1, (unsigned char*)&blocknum, sizeof(blocknum), 0) ;
    //------------------------Hfinal = H(H0, block)-----

    CryptDeriveKey(hCryptProv, CALG_RC4, hHash1, 0x00280000, hKey);

    if(hHash1 != 0) CryptDestroyHash(hHash1);
    if(pbSaltandPwdHash != NULL) free(pbSaltandPwdHash);

    return 0;
} 
int-getEncrypKey(HCRYPTKEY*hKey,int-blocknum)
{
//------------------------H0=H(盐,密码)-----
字节*pbSaltandPwdHash=NULL;
DWORD dwSaltandPwdLen=0;
pbSaltandPwdHash=SHA1_2(psalt,16,ppwd,strlen(pwd)/2和dwSaltandPwdLen);
printf(“SaltandPwd的SHA1:\n”);
for(DWORD i=0;i

我知道如何在linux下获取
H0
,但我不知道如何获取
hHash1
hKey
,这篇文章听起来好像做了同样的事情:

在openssl中生成哈希的更通用方法如下:

在你做任何事情之前:

#include <ssl/evp.h>

int main(int argc, char argv[]) // or in an "initialise" type function
{
     OpenSSL_add_all_digests()
     ...
}

1) 这与你之前的问题有什么不同?2) 从MS的crypto API移植到另一个crypto API(例如OpenSSL)的哪一部分会给您带来问题?@CodesIn混沌我想我必须有相同的API,如
CryptCreateHash
CryptHashData
,以及相同的结构,如
HCRYPTKEY
,来解密MS加密的office文档。然而,我现在理解并解决了它。感谢您的关注。是的,这几乎就是我想要的,在散列后获取解密密钥。因此,下面的一些调用,如
RC4\u set\u key
获取我的答案。谢谢您的答案。
const EVP_MD *digest;
EVP_MD_CTX context;
unsigned char hash[EVP_MAX_MD_SIZE];
unsigned int hash_len;

digest = EVP_get_digestbyname("sha1"); /* choose the hash type here */

EVP_MD_CTX_init(&context);
EVP_DigestInit_ex(&contxt, digest, NULL);
EVP_DigestUpdate(&context, pbSaltandPwdHash, dwSaltandPwdLen);
EVP_DigestUpdate(&context, &blocknum, sizeof(blocknum));
EVP_DigestFinal_ex(&context, hash, &hash_len);
EVP_MD_CTX_cleanup(&context);

/* Now use hash and hash_len as required */