Encryption & Decryption with office files
This method works only for notepad files.
i want it to mainly work with office files.
when i decrypt i want to generate the original office file which i encrypted. but this code after decryption generates the decrypted version of offcie file in a notepad file and also has a lot of junk characters in it.
If this doesnot work is there any other way out. Probably using APIs
Please help
----encryption----------
Public Function funcencrypt(PassText As String) As String
Dim lpos As Long ' For Iterating through each byte in Source File
Dim bdata As Byte ' For Reading Data from Source File
Dim bdatac As Byte ' For storing Complemented (or encrypted) bData
lpos = 1
'opening the file where encrypted data will be stored
Open PassText & ".encrypted" For Binary Access Write As #2
'opening the source file to be encrypted
Open PassText For Binary Access Read As #1
Do While Not EOF(1)
Get #1, lpos, bdata 'Reading Data Byte by Byte from Source File
bdatac = Not (bdata) 'Encryption of the Data
If Not bdatac = 255 Then
Put #2, lpos, bdatac 'Writing Encrypted Data To Temporary Destination File
End If
lpos = lpos + 1
Loop
Close #1
Close #2
End Function
------------Decryption---------------------
Public Function funcdecrypt(PassText As String) As String
Dim lpos As Long ' For Iterating through each byte in Source File
Dim bdata As Byte ' For reading data from the temporary file
Dim bdatac As Byte ' for storing data to another temporary file
lpos = 1
'opening the file where decrypted data will be stored
Open PassText & ".encrypted" For Binary Access Write As #2
Open PassText For Binary Access Read As #1
Do While Not EOF(1)
Get #1, lpos, bdata
bdatac = Not (bdata)
If Not bdatac = 255 Then
Put #2, lpos, bdatac
End If
lpos = lpos + 1
Loop
Close #1
Close #2
End Function
Re: Encryption & Decryption with office files
Got your PM. Welcome to the forums.
Isn't it the same if you displayed the unencrypted WORD file in a textbox?
Lots of junk characters that WORD uses, so it'd be the same when it was decrpted.
Hope you found the CodeBank thread on CAPICOM. I think I read somewhere that you could encrypt and decrypt files instead of string. I don't have a link though.