1 | #Region "Microsoft.VisualBasic::83c95f589d1abbd6cb9676d948dcf4e2, Microsoft.VisualBasic.Core\Extensions\Security\SecurityString.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Class SecurityStringModel |
35 | ' |
36 | ' Function: ToString |
37 | ' |
38 | ' Sub: (+2 Overloads) Dispose |
39 | ' Interface ISecurityStringModel |
40 | ' |
41 | ' Function: Decrypt, DecryptString, Encrypt, EncryptData |
42 | ' |
43 | ' |
44 | ' |
45 | ' |
46 | ' /********************************************************************************/ |
47 | |
48 | #End Region |
49 | |
50 | Imports System.Security.Cryptography |
51 | Imports System.Text |
52 | Imports Microsoft.VisualBasic.Scripting.MetaData |
53 | |
54 | Namespace SecurityString |
55 | |
56 | Public MustInherit Class SecurityStringModel |
57 | Implements System.IDisposable |
58 | Implements ISecurityStringModel |
59 | |
60 | Protected Friend strPassphrase As String = "<Guid(""768DF93E-AC45-4AD5-A0D9-C143CDA5BC55"")>" |
61 | |
62 | Public Overrides Function ToString() As String |
63 | Return strPassphrase |
64 | End Function |
65 | |
66 | Public MustOverride Function Encrypt(input() As Byte) As Byte() Implements ISecurityStringModel.Encrypt |
67 | Public MustOverride Function EncryptData(text As String) As String Implements ISecurityStringModel.EncryptData |
68 | Public MustOverride Function Decrypt(input() As Byte) As Byte() Implements ISecurityStringModel.Decrypt |
69 | Public MustOverride Function DecryptString(text As String) As String Implements ISecurityStringModel.DecryptString |
70 | |
71 | #Region "IDisposable Support" |
72 | Private disposedValue As Boolean ' To detect redundant calls |
73 | |
74 | ' IDisposable |
75 | Protected Overridable Sub Dispose(disposing As Boolean) |
76 | If Not Me.disposedValue Then |
77 | If disposing Then |
78 | ' TODO: dispose managed state (managed objects). |
79 | strPassphrase = "" |
80 | Call FlushMemory() |
81 | End If |
82 | |
83 | ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. |
84 | ' TODO: set large fields to null. |
85 | End If |
86 | Me.disposedValue = True |
87 | End Sub |
88 | |
89 | ' TODO: override Finalize() only if Dispose( disposing As Boolean) above has code to free unmanaged resources. |
90 | 'Protected Overrides Sub Finalize() |
91 | ' ' Do not change this code. Put cleanup code in Dispose( disposing As Boolean) above. |
92 | ' Dispose(False) |
93 | ' MyBase.Finalize() |
94 | 'End Sub |
95 | |
96 | ' This code added by Visual Basic to correctly implement the disposable pattern. |
97 | Public Sub Dispose() Implements IDisposable.Dispose |
98 | ' Do not change this code. Put cleanup code in Dispose(disposing As Boolean) above. |
99 | Dispose(True) |
100 | GC.SuppressFinalize(Me) |
101 | End Sub |
102 | #End Region |
103 | |
104 | Public Interface ISecurityStringModel |
105 | Function Encrypt(input() As Byte) As Byte() |
106 | Function EncryptData(text As String) As String |
107 | Function Decrypt(input() As Byte) As Byte() |
108 | Function DecryptString(text As String) As String |
109 | End Interface |
110 | |
111 | End Class |
112 | End Namespace |