1 | #Region "Microsoft.VisualBasic::50d02f66dd29aa0234d1e529680d063c, Microsoft.VisualBasic.Core\Extensions\Security\RSACrypto.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 RSACrypto |
35 | ' |
36 | ' Function: Decrypt, DecryptString, Encrypt, EncryptData |
37 | ' |
38 | ' |
39 | ' /********************************************************************************/ |
40 | |
41 | #End Region |
42 | |
43 | Imports System.IO |
44 | Imports System.Text |
45 | Imports System.Security.Cryptography |
46 | |
47 | Namespace SecurityString |
48 | |
49 | Public Class RSACrypto : Inherits SecurityString.SecurityStringModel |
50 | |
51 | Dim rsa As RSACryptoServiceProvider = New RSACryptoServiceProvider() |
52 | |
53 | Public Overrides Function Decrypt(encrypted() As Byte) As Byte() |
54 | Return rsa.Decrypt(encrypted, False) |
55 | End Function |
56 | |
57 | Public Overrides Function DecryptString(text As String) As String |
58 | Dim encrypted As Byte() = System.Text.ASCIIEncoding.UTF8.GetBytes(text) |
59 | Dim decText As String = System.Text.ASCIIEncoding.UTF8.GetString(encrypted) |
60 | Return decText |
61 | End Function |
62 | |
63 | Public Overrides Function Encrypt(input() As Byte) As Byte() |
64 | Return rsa.Encrypt(input, False) |
65 | End Function |
66 | |
67 | Public Overrides Function EncryptData(text As String) As String |
68 | Dim encrypted() As Byte = rsa.Encrypt(System.Text.ASCIIEncoding.UTF8.GetBytes(text), False) |
69 | Dim encText As String = System.Text.ASCIIEncoding.UTF8.GetString(encrypted) |
70 | Return encText |
71 | End Function |
72 | End Class |
73 | End Namespace |