MS DocumentViewer
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports System.IO
|
||||
Imports DigitalData.Services.EDMIService.Security
|
||||
|
||||
Namespace Methods.IDB.GetFileObject
|
||||
Public Class GetFileObjectMethod
|
||||
@@ -69,6 +70,29 @@ Namespace Methods.IDB.GetFileObject
|
||||
End Function
|
||||
|
||||
Private Function LoadFileContents(pFilePath As String) As Byte()
|
||||
Try
|
||||
Dim password = Environment.GetEnvironmentVariable("DD_FILE_ENCRYPTION_PASSWORD")
|
||||
If String.IsNullOrWhiteSpace(password) Then
|
||||
Logger.Warn("No encryption password set (DD_FILE_ENCRYPTION_PASSWORD). Attempting legacy plain read for file [{0}]", pFilePath)
|
||||
Return ReadPlain(pFilePath)
|
||||
End If
|
||||
|
||||
Try
|
||||
' Try decrypt first (preferred path)
|
||||
Logger.Debug("Attempting AES decrypt for file [{0}]", pFilePath)
|
||||
Return SecureFileHandler.DecryptFileToBytes(pFilePath, password)
|
||||
Catch exDec As Exception
|
||||
Logger.Warn("Decrypt failed for file [{0}]. Falling back to plain read. Reason: {1}", pFilePath, exDec.Message)
|
||||
Logger.Error(exDec)
|
||||
Return ReadPlain(pFilePath)
|
||||
End Try
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
Private Function LoadFileContents_Old(pFilePath As String) As Byte()
|
||||
Try
|
||||
Using oFileStream As New FileStream(pFilePath, FileMode.Open, FileAccess.Read)
|
||||
Using oMemoryStream As New MemoryStream()
|
||||
@@ -85,6 +109,15 @@ Namespace Methods.IDB.GetFileObject
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function ReadPlain(pFilePath As String) As Byte()
|
||||
Using oFileStream As New FileStream(pFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
|
||||
Using oMemoryStream As New MemoryStream()
|
||||
oFileStream.CopyTo(oMemoryStream)
|
||||
Return oMemoryStream.ToArray()
|
||||
End Using
|
||||
End Using
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user