Semplici funzioni di criptazione e decriptazione
Ecco due semplici (e, quindi, non il massimo della vita) funzioni per criptare e decriptare una stringa:
Private Function encryptData(ByVal sDataToEncrypt As String)
Dim arrEncryptedData() As Byte = Encoding.UTF8.GetBytes(sDataToEncrypt)
Dim i As Integer
For i = arrEncryptedData.GetLowerBound(0) To arrEncryptedData.GetUpperBound(0)
arrEncryptedData(i) = arrEncryptedData(i) Xor 255
Next
Return Convert.ToBase64String(arrEncryptedData)
End Function
Private Function decryptData(ByVal sDataToDecrypt As String)
Dim arrDecryptedData() As Byte = Convert.FromBase64String(sDataToDecrypt)
Dim i As Integer
For i = arrDecryptedData.GetLowerBound(0) To arrDecryptedData.GetUpperBound(0)
arrDecryptedData(i) = arrDecryptedData(i) Xor 255
Next
Return Encoding.UTF8.GetString(arrDecryptedData)
End Function
Nessun commento:
Posta un commento