加密高手入
HCRYPTPROV hProv = NULL;
HCRYPTKEY hKey = NULL;
HCRYPTHASH hHash = NULL;
PBYTE pbBuffer = NULL;
DWORD dwBufferLen = 0;
DWORD dwCount = 0;
BOOL status = FALSE;
// Get handle to the default provider.
if( !CryptAcquireContext( &hProv, NULL, NULL, PROV_RSA_FULL, 0 ) )
goto done;
// Encrypt the file with a session key derived from a password.
// Create a hash object.
if( !CryptCreateHash( hProv, CALG_MD5, 0, 0, &hHash ) )
goto done;
// Hash in the password data.
if( !CryptHashData( hHash, (const unsigned char *) pszHashKey, strlen( pszHashKey ), 0 ) )
goto done;
// Derive a session key from the hash object.
if( !CryptDeriveKey( hProv, ENCRYPT_ALGORITHM, hHash, 0, &hKey ) )
goto done;
// Destroy the hash object.
CryptDestroyHash( hHash );
hHash = 0;
dwBufferLen = strlen( pszIn );
dwCount = dwBufferLen;
// Allocate memory.
if( ( pbBuffer = (PBYTE) malloc( dwBufferLen ) ) == NULL )
goto done;
// Copy challenge into Buffer
strncpy( (char *) pbBuffer, pszIn, dwBufferLen );
// Encrypt data
if( !CryptEncrypt( hKey, 0, FALSE, 0, pbBuffer, &dwCount, dwBufferLen ) )
goto done;
上面这一段很通用的程序里,加密的结果会不会和机器和操作系统有关?
我怎么改称和机器和操作系统无关的。