简体   繁体   English

MS Office的解密

[英]decryption of MS office

I'm working on decryption of encrypted MS Excel(RC4 encryption with SHA1),password is already known.In vs2010,I've could decrypt it correctly,however,my program hasto work under both Win and linux.And I have no idea to get the encryption key under linux right now,which is something like below under Win: 我正在对加密的MS Excel(使用SHA1进行RC4加密)进行解密,密码是已知的。在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;
} 

I knew how to get H0 under linux,but I dont know how to get the hHash1 and hKey . 我知道如何在Linux下获得H0 ,但我不知道如何获得hHash1hKey

This post sounds like it does the same thing: Implement Windows CryptoAPI CryptDeriveKey Using OpenSSL APIs 这篇文章听起来像是在做同样的事情: 使用OpenSSL API实现Windows CryptoAPI CryptDeriveKey

A more general way of generating hashes in openssl is below: 在openssl中生成哈希的更一般的方法如下:

Before you do anything: 在您做任何事情之前:

#include <ssl/evp.h>

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

Then to generate the hash ( error checking omitted ): 然后生成哈希( 省略错误检查 ):

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 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM