 |
|
[C#.net] เอา Encryption กับ Decryption มาฝากเพื่อนๆ เผื่อใครอยากเอาไปใช้ครับ |
|
 |
|
|
 |
 |
|
แจ่มครับ ผมชอบจังกระทู้แบบนี้
|
 |
 |
 |
 |
Date :
2012-09-17 16:57:11 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนั้น เป็นการ Encode เป็น String Base 64 ไม่เกี่ยวกับ MD5 นี่ครับ
อีกอย่างคือ เราไม่สามารถ Decrypt ข้อมูลที่ถูก Encrypt แบบ MD5
|
ประวัติการแก้ไข 2012-09-18 09:19:13
 |
 |
 |
 |
Date :
2012-09-18 09:17:43 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หงะ จริงด้วย
MD5 ต้องมีพวก security key, hash key อะไรมายุ่งด้วย
กำลังลองจัดการอยู่
ไว้สำเร็จจะเอามาแชร์ใหม่ละกันนะครับ
|
 |
 |
 |
 |
Date :
2012-09-18 17:21:51 |
By :
mixarstudio |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สำหรับ VB.Net
Code (VB.NET)
Imports System.Security.Cryptography
Imports System.Text
Public Class MyScript
'Encryption
Public Function EncodePasswordToBase64(password As String) As String
Try
Dim encData_byte As Byte() = New Byte(password.Length - 1) {}
encData_byte = System.Text.Encoding.UTF8.GetBytes(password)
Dim encodedData As String = Convert.ToBase64String(encData_byte)
Return encodedData
Catch ex As Exception
Throw New Exception("Error in base64Encode" + ex.Message)
End Try
End Function
'Decryption
Public Function DecodeFrom64(encodedData As String) As String
Dim encoder As New System.Text.UTF8Encoding()
Dim utf8Decode As System.Text.Decoder = encoder.GetDecoder()
Dim todecode_byte As Byte() = Convert.FromBase64String(encodedData)
Dim charCount As Integer = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length)
Dim decoded_char As Char() = New Char(charCount - 1) {}
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0)
Dim result As String = New [String](decoded_char)
Return result
End Function
End Class
|
 |
 |
 |
 |
Date :
2017-01-11 12:53:26 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|