ورود

View Full Version : آموزش: ددانلود سورس پروژه رمزگذاری متن



ROSTAM2
یک شنبه 14 مرداد 1403, 14:51 عصر
سلام به همه

در این پروژه متن از کاربر گرفته می شه رمزگذاری و پارامترهای رمزگذاری بعنوان کلید در دیتابیس Keys ذخیره سازی می شه که مجدداً توسط همان پارامترها قابل بازیابی است....


Imports System.Security.Cryptography
Imports System.Text


Public Class ProtectPassword
Protected Friend Shared [Data] As New ProtectionEntities
Protected Friend Shared ByteConverter As New UnicodeEncoding()
''' <summary>
'''
''' </summary>
''' <param name="value">String to Protect</param>
''' <param name="ProtectedValue">Protected String converted from value</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function [New](value As String, ByRef ProtectedValue As String) As Guid
Dim KeyInfo As New Keys
Dim R As RSACryptoServiceProvider = RSACryptoServiceProvider.Create()
Dim ID As Guid = Guid.NewGuid
With R.ExportParameters(True)
KeyInfo.ID = ID
KeyInfo.PrivateExponent = .D
KeyInfo.exponent1 = .DP
KeyInfo.exponent2 = .DQ
KeyInfo.publicExponent = .Exponent
KeyInfo.coefficient = .InverseQ
KeyInfo.modulus = .Modulus
KeyInfo.prime1 = .P
KeyInfo.prime2 = .Q
End With
Data.AddToKeys(KeyInfo)
Data.Keys.Context.SaveChanges()
Data.AcceptAllChanges()
ProtectedValue = Convert.ToBase64String(R.Encrypt(ByteConverter.Get Bytes(value), False))
Return ID
End Function
Public Shared Function [New](value As String, ByRef ProtectedValue As Byte()) As Guid
Dim KeyInfo As New Keys
Dim R As RSACryptoServiceProvider = RSACryptoServiceProvider.Create()
Dim ID As Guid = Guid.NewGuid
With R.ExportParameters(True)
KeyInfo.ID = ID
KeyInfo.PrivateExponent = .D
KeyInfo.exponent1 = .DP
KeyInfo.exponent2 = .DQ
KeyInfo.publicExponent = .Exponent
KeyInfo.coefficient = .InverseQ
KeyInfo.modulus = .Modulus
KeyInfo.prime1 = .P
KeyInfo.prime2 = .Q
End With
Data.AddToKeys(KeyInfo)
Data.Keys.Context.SaveChanges()
Data.AcceptAllChanges()
ProtectedValue = R.Encrypt(ByteConverter.GetBytes(value), False)
Return ID
End Function
Public Shared Function Recover(KeyID As Guid, ProtectedValue As String) As String
Dim R As RSACryptoServiceProvider = RSACryptoServiceProvider.Create()
Dim Params As New RSAParameters
Dim KeyInfo As Data.Objects.ObjectQuery(Of Keys)
KeyInfo = Data.CreateQuery(Of Keys)("SELECT VALUE KEYS FROM KEYS WHERE KEYS.ID = @ID", New Objects.ObjectParameter("ID", KeyID))
If KeyInfo Is Nothing Then Return Nothing
With KeyInfo.FirstOrDefault
Params.D = .PrivateExponent
Params.DP = .exponent1
Params.DQ = .exponent2
Params.Exponent = .publicExponent
Params.InverseQ = .coefficient
Params.Modulus = .modulus
Params.P = .prime1
Params.Q = .prime2
R.ImportParameters(Params)
End With
Return ByteConverter.GetString(R.Decrypt(Convert.FromBase 64String(ProtectedValue), False))
End Function
Public Shared Function Recover(KeyID As Guid, ProtectedValue As Byte()) As String
Dim R As RSACryptoServiceProvider = RSACryptoServiceProvider.Create()
Dim Params As New RSAParameters
Dim KeyInfo As Data.Objects.ObjectQuery(Of Keys)
KeyInfo = Data.CreateQuery(Of Keys)("SELECT VALUE KEYS FROM KEYS WHERE KEYS.ID = @ID", New Objects.ObjectParameter("ID", KeyID))
If KeyInfo Is Nothing Then Return Nothing
With KeyInfo.FirstOrDefault
Params.D = .PrivateExponent
Params.DP = .exponent1
Params.DQ = .exponent2
Params.Exponent = .publicExponent
Params.InverseQ = .coefficient
Params.Modulus = .modulus
Params.P = .prime1
Params.Q = .prime2
R.ImportParameters(Params)
End With
Return ByteConverter.GetString(R.Decrypt(ProtectedValue, False))
End Function
End Class


155930
مشاهده ویدیوی آموزشی در کانال آپارات
(https://www.aparat.com/v/tjmlme5)
دانلود سورس پروژه در پیام رسان ایتا (https://eitaa.com/vbprogramming/601)