@Wqweto; Can you share the binary read and write codes: ReadBinaryFile and WriteBinaryFile?
baData = ReadBinaryFile("c:\path\to\input.file")
AesCryptArray baData, ToUtf8Array("pass")
WriteBinaryFile "c:\path\to\encrypted.file", baData
Printable View
@Wqweto; Can you share the binary read and write codes: ReadBinaryFile and WriteBinaryFile?
baData = ReadBinaryFile("c:\path\to\input.file")
AesCryptArray baData, ToUtf8Array("pass")
WriteBinaryFile "c:\path\to\encrypted.file", baData
Here you go
Can be used like thisCode:'--- mdBinaryFile.bas
Option Explicit
#Const HasPtrSafe = (VBA7 <> 0) Or (TWINBASIC <> 0)
#If HasPtrSafe Then
Private Declare PtrSafe Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
#Else
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
#End If
Public Function ReadBinaryFile(sFile As String) As Byte()
Dim baBuffer() As Byte
Dim nFile As Integer
On Error GoTo EH
baBuffer = vbNullString
nFile = FreeFile
Open sFile For Binary Access Read Shared As nFile
If LOF(nFile) > 0 Then
ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
Get nFile, , baBuffer
End If
Close nFile
ReadBinaryFile = baBuffer
EH:
End Function
Public Sub WriteBinaryFile(sFile As String, baBuffer() As Byte)
Dim nFile As Integer
Call DeleteFile(sFile)
nFile = FreeFile
Open sFile For Binary Access Write Shared As nFile
If UBound(baBuffer) >= 0 Then
Put nFile, , baBuffer
End If
Close nFile
End Sub
Btw, just updated the the mdAesCtr.bas with some small fixes.Code:Private Sub TestBinary()
Const IN_FILE As String = "D:\TEMP\aaa.txt"
Dim baData() As Byte
baData = ReadBinaryFile(IN_FILE)
AesCryptArray baData, ToUtf8Array("pass")
WriteBinaryFile IN_FILE & ".encrypted", baData
baData = ReadBinaryFile(IN_FILE & ".encrypted")
AesCryptArray baData, ToUtf8Array("pass")
WriteBinaryFile IN_FILE & ".decrypted", baData
End Sub
cheers,
</wqw>
Hi wqweto
thanks for the excellent work and for sharing the code
cheers
Tiz
Unfortunately MSSQL does not support creating/importing symmetric keys with prepared values for keys and IVs. It uses some weird scheme with KEY_SOURCE strings which is probably PBKDF2 based but not documented.
In recent SQL 2022 there are BACKUP/RESTORE ASYMMETRIC KEY statements but it's not clear what the format of these backup files is and I'm not sure whether using .pfx containers is a possibility here.
Edit: On second glance, there is no backup/restore for *symmetric* keys needed for AES so even these new statements (in .pfx format) cannot help.
cheers,
</wqw>