pgp -шифрование
#39218866
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
ЕвгенийВ,
спасибо огромное!!! С помощью этой статьи и сайта http://www.carlosag.net/tools/codetranslator/
написал на VB.net.
Если кому- то понадобится код:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81.
Imports Starksoft.Cryptography.OpenPGP
Imports System.IO
Imports ClassLibrary1.cls
Module my_int
'Imports System.Text
Public Class EncryptionService
Implements IEncryptionService
Private gpg As GnuPG = New GnuPG
Private appPath As String
#Region "Constructors"
Public Sub New()
MyBase.New
End Sub
Public Sub New(ByVal appPath As String)
MyBase.New
Me.appPath = Me.appPath
End Sub
#End Region
Public Function DecryptFile(ByVal encryptedSourceFile As String, ByVal decryptedFile As String) As FileInfo
' check parameters
If String.IsNullOrEmpty(encryptedSourceFile) Then
Throw New ArgumentException("encryptedSourceFile parameter is either empty or null", "encryptedSourceFile")
End If
If String.IsNullOrEmpty(decryptedFile) Then
Throw New ArgumentException("decryptedFile parameter is either empty or null", "decryptedFile")
End If
Dim encryptedSourceFileStream As FileStream = New FileStream(encryptedSourceFile, FileMode.Open)
' make sure the stream is at the start.
encryptedSourceFileStream.Position = 0
Dim decryptedFileStream As FileStream = New FileStream(decryptedFile, FileMode.Create)
' Specify the directory containing gpg.exe (again, not sure why).
Me.gpg.BinaryPath = Path.GetDirectoryName(Me.appPath)
' Decrypt
Me.gpg.Decrypt(encryptedSourceFileStream, decryptedFileStream)
Return New FileInfo(decryptedFile)
End Function
Public Function EncryptFile(ByVal keyUserId As String, ByVal sourceFile As String, ByVal encryptedFile As String) As FileInfo
' check parameters
If String.IsNullOrEmpty(keyUserId) Then
Throw New ArgumentException("keyUserId parameter is either empty or null", "keyUserId")
End If
If String.IsNullOrEmpty(sourceFile) Then
Throw New ArgumentException("sourceFile parameter is either empty or null", "sourceFile")
End If
If String.IsNullOrEmpty(encryptedFile) Then
Throw New ArgumentException("encryptedFile parameter is either empty or null", "encryptedFile")
End If
Dim sourceFileStream As Stream = New FileStream(sourceFile, FileMode.Open)
Dim encryptedFileStream As Stream = New FileStream(encryptedFile, FileMode.Create)
' Specify the directory containing gpg.exe (not sure why).
' Me.gpg.BinaryPath = Path.GetDirectoryName(Me.appPath)
Me.gpg.BinaryPath = Path.GetDirectoryName("C:\Program Files\GNU\GnuPG\pub\")
Me.gpg.Recipient = keyUserId
' Perform encryption
Me.gpg.Encrypt(sourceFileStream, encryptedFileStream)
Return New FileInfo(encryptedFile)
End Function
Private Function IEncryptionService_EncryptFile(keyUserId As String, sourceFile As String, encryptedFile As String) As FileInfo Implements IEncryptionService.EncryptFile
Throw New NotImplementedException()
End Function
Private Function IEncryptionService_DecryptFile(encryptedSourceFile As String, decryptedFile As String) As FileInfo Implements IEncryptionService.DecryptFile
Throw New NotImplementedException()
End Function
End Class
End Module
И чтобы зашифровать вызываем следующий код
1. 2.
Dim p As New EncryptionService
Call p.EncryptFile("xxxxxx", fileName, fileNameOut)
|
|