显示64位字符错误 [英] show error for 64bit character

查看:82
本文介绍了显示64位字符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..

我使用下面给出的加密和解密功能,但不适用于64位字符.

请帮我该怎么办,使其在任何地方都可以完美运行,或者如果有人具有更好的加密和解密功能,可以为我提供.


Hello Everyone..

I use encryption and decryption function given bellow but it not working for 64 bit character.

Please help me what can i do so it works perfect anywhere or if any one have better function for encryption and decryption can you provide me it.


Public Shared Function EncryptText(ByVal strText As String) As String
      Return Encrypt(strText, "&%#@?,:*")
  End Function

  'Decrypt the text
  Public Shared Function DecryptText(ByVal strText As String) As String
      Return Decrypt(strText, "&%#@?,:*")
  End Function

  'The function used to encrypt the text
  Private Shared Function Encrypt(ByVal strText As String, ByVal strEncrKey As String) As String
      Dim byKey() As Byte = {}
      Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}

      Try
          byKey = System.Text.Encoding.UTF8.GetBytes(Left(strEncrKey, 8))

          Dim des As New DESCryptoServiceProvider
          Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(strText)
          Dim ms As New MemoryStream
          Dim cs As New CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write)
          cs.Write(inputByteArray, 0, inputByteArray.Length)
          cs.FlushFinalBlock()
          Return Convert.ToBase64String(ms.ToArray())

      Catch ex As Exception
          Return ex.Message
      End Try

  End Function

  'The function used to decrypt the text
  Private Shared Function Decrypt(ByVal strText As String, ByVal sDecrKey As String) As String
      Dim byKey() As Byte = {}
      Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
      Dim inputByteArray(strText.Length) As Byte

      Try
          byKey = System.Text.Encoding.UTF8.GetBytes(Left(sDecrKey, 8))
          Dim des As New DESCryptoServiceProvider
          inputByteArray = Convert.FromBase64String(strText)
          Dim ms As New MemoryStream
          Dim cs As New CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write)

          cs.Write(inputByteArray, 0, inputByteArray.Length)
          cs.FlushFinalBlock()
          Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8

          Return encoding.GetString(ms.ToArray())

      Catch ex As Exception
          Return ex.Message
      End Try

  End Function



谢谢.. !!



Thank you..!!

推荐答案

有关其他形式的加密,请参见

.NET Encryption Simplified [ Google 是您最好的朋友.
For other forms of encryption see

.NET Encryption Simplified[^]

And Google is your best friend.


UTF-8是可变长度的,这将对其进行解释并提供解决方案:
http://msdn.microsoft.com/zh-cn/library/system.text.encoding.utf8%28v = vs.80%29.aspx [
UTF-8 is variable length, this will explain it and provide a solution:
http://msdn.microsoft.com/en-us/library/system.text.encoding.utf8%28v=vs.80%29.aspx[^]

Good luck!


这篇关于显示64位字符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆