2

Am attempting to encrypt a file using this program in QB64.

It does not actually encrypt the file and always returns successful. Why?

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
eoredson
  • 1,167
  • 2
  • 14
  • 29
  • 1
    Obviously you're calling it correctly, so it's a matter of why your C++ code doesn't work, not why the QB64 code doesn't work. –  Aug 28 '16 at 13:41
  • Nevermind. The target file is being encrypted: only transparent to the user who encrypted it and don't see any binary-like text. – eoredson Sep 02 '16 at 02:16

1 Answers1

1

The solution was to detect the encryption status of a filename such as this:

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
eoredson
  • 1,167
  • 2
  • 14
  • 29