2

我正在尝试使用 QB64 中的此程序加密文件。

它实际上并不加密文件并且总是返回成功。为什么?

DECLARE LIBRARY
    FUNCTION EncryptFile (f$)
    FUNCTION DecryptFile (f$, BYVAL f&)
END DECLARE
PRINT "Enter filename";
INPUT f$
IF f$ <> "" THEN
    f$ = f$ + CHR$(0)
    x = EncryptFile(f$)
    IF x = 0 THEN
        PRINT "Error encrypting file."
    ELSE
        PRINT "File encrypted."
    END IF
END IF
END
4

1 回答 1

1

解决方案是检测文件名的加密状态,例如:

REM checks encryption status of a filename
DECLARE DYNAMIC LIBRARY "advapi32"
    FUNCTION FileEncryptionStatusA% (f$, f&)
END DECLARE
DO
    PRINT "Filename";
    INPUT f$
    IF f$ = "" THEN END
    x = FileEncryptionStatusA(f$, f&)
    IF x = 0 THEN
        PRINT "Error accessing file."
    END IF
    IF x THEN
        SELECT CASE f&
            CASE 0
                PRINT "File can be encrypted."
            CASE 1
                PRINT "File is encrypted."
            CASE 2
                PRINT "File is system."
            CASE 3
                PRINT "File is root."
            CASE 4
                PRINT "File is system directory."
            CASE 5
                PRINT "Encryption status unknown."
            CASE 6
                PRINT "File system does not support encryption."
            CASE 7 ' reserved
            CASE 8
                PRINT "File is read-only."
        END SELECT
    END IF
LOOP
END
于 2016-11-08T23:18:21.450 回答