如何在 QB64 中加密文件

How To Encrypt File In QB64

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

它实际上并没有加密文件并且总是returns成功。为什么?

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

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

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