📄 kgsha.cpp
字号:
break; } } else { BYTE tmpKey[ MAXIMUM_KEY_SIZE_BYTES + 4 ]; if ( ((*ErrorCode) = GetPasswordWithVerification( "Changing password for hidden part!",//text "Enter new password: "/*Caption*/, newPassword )) != ERROR_NO ) { break; } // Check if password for hidden part is the same as for original part while ( (DataBlockVerifyPasswordAndGetKey( *DataBlock,Alg, AlgKeyLength, newPassword, tmpKey, pool ) ) == ERROR_NO ) { ShredData( tmpKey, MAXIMUM_KEY_SIZE_BYTES + 4); if ( ((*ErrorCode) = GetPasswordWithVerification( "WARNING: Entered password equal main container password!",//text "Enter new password: "/*Caption*/, newPassword )) != ERROR_NO ) { break; } } ShredData( tmpKey, MAXIMUM_KEY_SIZE_BYTES + 4); if ( *ErrorCode != ERROR_NO ) { break; } *ErrorCode = DataBlockWriteKey_Hidden(*DataBlock, Alg, AlgKeyLength, newPassword, key, KATTRIBUTE_KEY_EMPTY, pool, offset, &mask, kbPosition); if ( *ErrorCode != ERROR_NO ) break; } *ErrorCode = ERROR_NO; bResult = TRUE; break; // ************** Add new password for Regular or Hidden container *************** case CFLAG_ADD_NEW_PASSWORD: if ( ((*ErrorCode) = DataBlockCheck(*DataBlock, *DataSize, Alg.alg_id)) != ERROR_NO ) { break; } *ErrorCode = DataBlock_CheckFreeSpaceForNewPassword( *DataBlock ); if ( (*ErrorCode) == ERROR_NOT_ENOUGH_SPACE_FOR_KEY ) { bResult = FALSE; break; }// LoadString( hModule, IDS_ENTER_EXISTING_PASSWORD, msgText, sizeof(msgText) ); if ( ((*ErrorCode) = GetPassword(Text, "Enter existing password: ", password )) != ERROR_NO ) { break; } bHidPart = FALSE; if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey( *DataBlock, Alg, AlgKeyLength, password, key, pool ) ) != ERROR_NO ) { // May be, we are going to change password for hidden part? if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey_Hidden( *DataBlock, Alg, AlgKeyLength, password, key, pool, &offset, &mask, &kbPosition ) ) != ERROR_NO ) { break; // It is not a password for hidden part :-( } else {// LoadString( hModule, IDS_NewHidPasswordWarning, msgText, sizeof(msgText) );// LoadString( hModule, IDS_WARNING, captionText, sizeof(captionText) );// int iRes = MessageBox( hWndParent, msgText, captionText, MB_YESNO | MB_ICONWARNING );// if (iRes == IDNO)// {// *ErrorCode = ERROR_CANCELLED_BY_USER;// break;// } bHidPart = TRUE; } }// LoadString( hModule, IDS_WARNING, captionText, sizeof(captionText) ); for ( ;; ) {// LoadString( hModule, IDS_EnterAdditionalPassword, msgText, sizeof(msgText) ); if ( ((*ErrorCode) = GetPasswordWithVerification(Text, "Enter additional password: ", newPassword)) != ERROR_NO ) { break; } // Check if such new password was added earlier - nothing to do in this case if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey( *DataBlock, Alg, AlgKeyLength, newPassword, tmpKey, pool )) == ERROR_NO ) { if ( bHidPart ) {// LoadString( hModule, IDS_PASSWORD_IN_USE, msgText, sizeof(msgText) );// MessageBox( hWndParent, msgText, captionText, MB_OK | MB_ICONWARNING ); Text = "This password already in use!"; continue; } else { break; // such password was added earliar - nothing to do } } if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey_Hidden( *DataBlock, Alg, AlgKeyLength, newPassword, key, pool, &offset, &mask, &kbPosition ) ) == ERROR_NO ) { if ( bHidPart ) { break; // such password was added earliar - nothing to do } else {// LoadString( hModule, IDS_PASSWORD_IN_USE, msgText, sizeof(msgText) );// MessageBox( hWndParent, msgText, captionText, MB_OK | MB_ICONWARNING ); Text = "This password already in use!"; continue; } } break; } ShredData( tmpKey, MAXIMUM_KEY_SIZE_BYTES + 4); if ( ((*ErrorCode) == ERROR_NO) || // such password was added earliar - nothing to do ((*ErrorCode) == ERROR_CANCELLED_BY_USER) ) // process is cancelled { bResult = TRUE; break; } if ( !bHidPart ) { *ErrorCode = DataBlockAddPassword( DataBlock, DataSize, Alg, AlgKeyLength, newPassword, key, KATTRIBUTE_KEY_FULL, pool ); } else { *ErrorCode = DataBlockAddPassword_Hidden(DataBlock, DataSize, Alg, AlgKeyLength, newPassword, key, KATTRIBUTE_KEY_EMPTY, pool, offset, &mask ); // update mask in the call if ( (*ErrorCode) == ERROR_NO ) { *ErrorCode = DataBlockWriteKey_Hidden(*DataBlock, Alg, AlgKeyLength, password, key, KATTRIBUTE_KEY_EMPTY, pool, offset, &mask, kbPosition); // write updated mask to original Key Block } } if ( (*ErrorCode) == ERROR_NOT_ENOUGH_SPACE_FOR_KEY ) {// LoadString( hModule, IDS_ERROR, captionText, sizeof(captionText) );// LoadString( hModule, IDS_NoFreeSpaceToAddPassword, msgText, sizeof(msgText) );// MessageBox( hWndParent, msgText, captionText, MB_OK | MB_ICONWARNING );// *ErrorCode = ERROR_NO; break; } if ( *ErrorCode != ERROR_NO ) break; bResult = TRUE; break; case CFLAG_REMOVE_ADDITIONAL_PASSWORD: bResult = FALSE; if ( ((*ErrorCode) = DataBlockCheck(*DataBlock, *DataSize, Alg.alg_id)) != ERROR_NO ) { break; } for ( iAttempts=0; iAttempts<3; iAttempts++ ) {// LoadString( hModule, IDS_EnterAdditionalPasswordToDelete, msgText, sizeof(msgText) ); if ( ((*ErrorCode) = GetPassword( Text, "Enter additional password to delete: ", password )) != ERROR_NO ) { *ErrorCode = ERROR_NO; break; } // Check if we have entered password for hidden part. // If so, refuse to delete it if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey_Hidden( *DataBlock, Alg, AlgKeyLength, password, key, pool, &offset, &mask, &kbPosition ) ) == ERROR_NO ) {// LoadString( hModule, IDS_CannotDeleteHiddenPassword, msgText, sizeof(msgText) );// LoadString( hModule, IDS_WARNING, captionText, sizeof(captionText) );// MessageBox( hWndParent, msgText, captionText, MB_OK | MB_ICONWARNING ); Text = "Can not delete hidden password!!!"; *ErrorCode = ERROR_NO; continue; } *ErrorCode = DataBlockRemoveAdditionalPassword( *DataBlock, Alg, AlgKeyLength, password, key, pool ); if ( (*ErrorCode) == ERROR_INCORRECT_PASSWORD ) {// LoadString( hModule, IDS_INCORRECT_PASSWORD, msgText, sizeof(msgText) );// LoadString( hModule, IDS_WARNING, captionText, sizeof(captionText) );// MessageBox( hWndParent, msgText, captionText, MB_OK | MB_ICONWARNING ); *ErrorCode = ERROR_NO; Text = "Incorrect password!"; continue; } else if ( (*ErrorCode) == ERROR_MASTER_PASSWORD_ENTERED ) {// LoadString( hModule, IDS_CannotDeleteMasterPassword, msgText, sizeof(msgText) );// LoadString( hModule, IDS_WARNING, captionText, sizeof(captionText) );// MessageBox( hWndParent, msgText, captionText, MB_OK | MB_ICONWARNING ); *ErrorCode = ERROR_NO; Text = "Master password can not be deleted!"; continue; } else if ( (*ErrorCode) == ERROR_NO ) {// LoadString( hModule, IDS_SuccessInDeletePassword, msgText, sizeof(msgText) );// LoadString( hModule, IDS_INFORMATION, captionText, sizeof(captionText) );// MessageBox( hWndParent, msgText, captionText, MB_OK | MB_ICONWARNING ); break; } } if ( (*ErrorCode) == ERROR_NO ) bResult = TRUE; break; // ************** Create Hidden part *************** case CFLAG_CREATE_HIDDEN_PART: if ( ((*ErrorCode) = DataBlockCheck(*DataBlock, *DataSize, Alg.alg_id)) != ERROR_NO ) { break; } *ErrorCode = DataBlock_CheckFreeSpaceForNewPassword( *DataBlock ); if ( (*ErrorCode) == ERROR_NOT_ENOUGH_SPACE_FOR_KEY ) { bResult = FALSE; break; } if ( ((*ErrorCode) = GetPassword(Text, "Enter existing password: ", password )) != ERROR_NO ) { break; } if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey( *DataBlock, Alg, AlgKeyLength, password, tmpKey, pool ) ) != ERROR_NO ) { bResult = FALSE; break; } for ( ;; ) { if ( ((*ErrorCode) = GetPasswordWithVerification(Text, "Enter password for hidden part: ", newPassword)) != ERROR_NO ) { break; } // Check if such new password was added earlier - nothing to do in this case if ( ((*ErrorCode) = DataBlockVerifyPasswordAndGetKey( *DataBlock, Alg, AlgKeyLength, newPassword, tmpKey, pool )) == ERROR_NO )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -