📄 kgsha.cpp
字号:
{ Text = "This password already in use!"; continue; }else *ErrorCode = ERROR_NO;/* if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey_Hidden( *DataBlock, Alg, AlgKeyLength, newPassword, tmpKey, pool, &offset, &mask, &kbPosition ) ) == ERROR_NO ) { *ErrorCode = ERROR_HID_PASSWORD_INVALID; }*/ break; } if ( *ErrorCode != ERROR_NO ) break; if ( ((*ErrorCode) = GetSeedValue( seed, SEED_LENGTH )) != ERROR_NO ) break; *ErrorCode = ERROR_INTERNAL_PROBLEM; // assume the error will occur if ( GenerateKey(key, MAXIMUM_KEY_SIZE_BYTES, seed, SEED_LENGTH) != ERROR_NO ) break; mask = 0, kbPosition = 0; if ( ((*ErrorCode) = DataBlockWriteKey_Hidden(*DataBlock, Alg, AlgKeyLength, newPassword, key, KATTRIBUTE_KEY_EMPTY, pool, *DataOffset, &mask, HIDDEN_POSITION_ANY)) != ERROR_NO ) break; /* verify all that we did before */ if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey_Hidden( *DataBlock, Alg, AlgKeyLength, newPassword, key, pool, &offset, &mask, &kbPosition ) ) != ERROR_NO ) { break; } if ( *ErrorCode != ERROR_NO ) break; bResult = TRUE; break; default: *ErrorCode = ERROR_INCORRECT_CREATE_FLAG; bResult = FALSE; break; } ShredData( (BYTE *)password, PASSWORD_MAXIMUM_LENGTH ); ShredData( (BYTE *)newPassword, PASSWORD_MAXIMUM_LENGTH ); ShredData( key, MAXIMUM_KEY_SIZE_BYTES ); Free( seed, password, newPassword, key, pool ); return bResult;}extern "C" BOOL CreateKeyHandle( ALG_SERV Alg, /* what Encryption Algorithm will use the encryption key */ DWORD AlgKeyLength, /* encryption key length for the Encryption Algorithm */ char *Text, /* Text, containing filename of the container */ char *Caption, /* Caption of the "get password" dialog window */ DWORD CreateFlag, /* whether to create new key or open existing */ BYTE **vDataBlock, /* block of data that is stored inside file-container in encrypted form */ DWORD *DataSize, /* size of the block of data */ DWORD *KeyHandle, /* returned Key Handle */ DWORD *ErrorCode /* if the function returns FALSE, look on the Error code */ ){ DWORD DataOffset; return CreateKeyHandleEx(Alg,AlgKeyLength,Text,Caption,CreateFlag, vDataBlock,DataSize,KeyHandle,ErrorCode,&DataOffset);}#if 0extern "C" BOOL CreateKeyHandle( ALG_SERV Alg, /* what Encryption Algorithm will use the encryption key */ DWORD AlgKeyLength, /* encryption key length for the Encryption Algorithm */ char *Text, /* Text, containing filename of the container */ char *Caption, /* Caption of the "get password" dialog window */ DWORD CreateFlag, /* whether to create new key or open existing */ BYTE **vDataBlock, /* block of data that is stored inside file-container in encrypted form */ DWORD *DataSize, /* size of the block of data */ DWORD *KeyHandle, /* returned Key Handle */ DWORD *ErrorCode /* if the function returns FALSE, look on the Error code */ ){ BOOL bResult; BYTE *key, *seed, *pool; char *password, *newPassword; DATA_BLOCK **DataBlock = (DATA_BLOCK **)vDataBlock; key = seed = NULL; password = newPassword = NULL; if ( !Allocate( &seed, &password, &newPassword, &key, &pool ) ) { *ErrorCode = ERROR_INTERNAL_PROBLEM; return FALSE; } bResult = FALSE; // Assume error will occur // Test if given algorithm can be called if ( alg_verify( Alg ) ) { *ErrorCode = ERROR_INVALID_ALGORITHM; Free( seed, password, newPassword, key, pool ); return FALSE; } if ( !(CORRECT_CFLAG(CreateFlag)) ) { *ErrorCode = ERROR_INCORRECT_CREATE_FLAG; Free( seed, password, newPassword, key, pool ); return FALSE; } switch ( CreateFlag ) { case CFLAG_CREATE_WITH_SINGLE_PASSWORD: if ( !DataBlockAllocate( DataBlock, DataSize, Alg.alg_id) ) { *ErrorCode = ERROR_INTERNAL_PROBLEM; break; } if ( ((*ErrorCode) = GetPasswordWithVerification( Text, Caption, password )) != ERROR_NO ) { DataBlockFree( DataBlock ); break; } if ( ((*ErrorCode) = GetSeedValue( seed, SEED_LENGTH )) != ERROR_NO ) { DataBlockFree( DataBlock ); break; } if ( GenerateKey(key, MAXIMUM_KEY_SIZE_BYTES, seed, SEED_LENGTH) != ERROR_NO ) { *ErrorCode = ERROR_INTERNAL_PROBLEM; DataBlockFree( DataBlock ); break; } if ( DataBlockWriteKey(*DataBlock, Alg, AlgKeyLength, password, key, KATTRIBUTE_KEY_FULL, pool) != ERROR_NO ) { DataBlockFree( DataBlock ); *ErrorCode = ERROR_INTERNAL_PROBLEM; break; } /* verify all that we did before */ if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey( *DataBlock, Alg, AlgKeyLength, password, key, pool ) ) != ERROR_NO ) { break; } // Call Algorithm driver for expanding and storing the Key if ( alg_make_key(Alg, key, AlgKeyLength, pool, KeyHandle) ) { *ErrorCode = ERROR_INVALID_ALGORITHM; DataBlockFree( DataBlock ); break; } *ErrorCode = ERROR_NO; bResult = TRUE; break; case CFLAG_VERIFY_AND_LOAD_KEY: // 1 - minimum number of keys inside the block if ( ((*ErrorCode) = DataBlockCheck(*DataBlock, *DataSize, Alg.alg_id)) != ERROR_NO ) { break; } if ( ((*ErrorCode) = GetPassword( Text, Caption, password )) != ERROR_NO ) { break; } if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey( *DataBlock, Alg, AlgKeyLength, password, key, pool ) ) != ERROR_NO ) { break; } // Call Algorithm driver for expanding and storing the Key if ( alg_make_key(Alg, key, AlgKeyLength, pool, KeyHandle) ) { *ErrorCode = ERROR_INVALID_ALGORITHM; break; } *ErrorCode = ERROR_NO; bResult = TRUE; break; case CFLAG_CHANGE_PASSWORD: if ( ((*ErrorCode) = DataBlockCheck(*DataBlock, *DataSize, Alg.alg_id)) != ERROR_NO ) { break; } if ( ((*ErrorCode) = GetPassword( Text, "Enter old password: "/*Caption*/, password )) != ERROR_NO ) { break; } if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey( *DataBlock, Alg, AlgKeyLength, password, key, pool ) ) != ERROR_NO ) { break; } if ( ((*ErrorCode) = GetPasswordWithVerification( Text, "Enter new password: "/*Caption*/, newPassword )) != ERROR_NO ) { break; } if ( ((*ErrorCode) = DataBlockChangePassword( *DataBlock, Alg, AlgKeyLength, password, newPassword, pool )) != ERROR_NO ) { break; } *ErrorCode = ERROR_NO; bResult = TRUE; break; default: *ErrorCode = ERROR_INCORRECT_CREATE_FLAG; bResult = FALSE; break; } ShredData( (BYTE *)password, PASSWORD_MAXIMUM_LENGTH ); ShredData( (BYTE *)newPassword, PASSWORD_MAXIMUM_LENGTH ); ShredData( key, MAXIMUM_KEY_SIZE_BYTES ); Free( seed, password, newPassword, key, pool ); return bResult;}#endif/******************************************************* * * FreeDataBlock() - frees the memory allocated when * user calls CreateKeyHandle() procedure with * CreateFlag equal to CFLAG_CREATE_WITH_SINGLE_PASSWORD * *******************************************************/extern "C" DWORD FreeDataBlock( BYTE **vDataBlock ){ if ( !DataBlockFree( (DATA_BLOCK **)vDataBlock ) ) return ERROR_INTERNAL_PROBLEM; return ERROR_NO;}/******************************************************* * * FreeKeyHandle() - frees the memory allocated for * encryption key inside algorithm driver when user calls * CreateKeyHandle() procedure with CreateFlag equal to * CFLAG_CREATE_WITH_SINGLE_PASSWORD or * CFLAG_VERIFY_AND_LOAD_KEY * *******************************************************/extern "C" DWORD FreeKeyHandle( ALG_SERV Alg, DWORD KeyHandle ){ if ( alg_free_key( Alg, KeyHandle ) ) return ERROR_INTERNAL_PROBLEM; return ERROR_NO;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -