当前位置: 代码迷 >> Windows Mobile >> WM6加密解密程序在手机上运行报错(在winForm上可以),VB.NET解决思路
  详细解决方案

WM6加密解密程序在手机上运行报错(在winForm上可以),VB.NET解决思路

热度:41   发布时间:2016-04-25 07:45:37.0
WM6加密解密程序在手机上运行报错(在winForm上可以),VB.NET
错误1:没有为“Public Overridable Function GetString(bytes() As Byte, index As Integer, count As Integer) As String”的参数“count”指定参数。

类的代码如下(红色地方报错):
[code=VB.NET][/code]
Imports System
Imports System.IO
Imports System.Security.Cryptography
Imports System.Text


Public Class Csmode
  Public Function Encrypt(ByVal StrInput As String) As String
  Dim ByteInput As [Byte]() = Encoding.Default.GetBytes(StrInput)
  Dim Ms As New System.IO.MemoryStream
  Dim DESC As New DESCryptoServiceProvider
  Dim CStream As New CryptoStream(Ms, DESC.CreateEncryptor(Encoding.Default.GetBytes("20000000"), Encoding.Default.GetBytes("字节数量")), CryptoStreamMode.Write)
  CStream.Write(ByteInput, 0, ByteInput.Length)
  CStream.FlushFinalBlock()
  Return Convert.ToBase64String(Ms.ToArray)
  End Function

  Public Function Decrypt(ByVal StrInput As String) As String
  Dim ByteInput As [Byte]() = Convert.FromBase64String(StrInput)
  Dim ms As New System.IO.MemoryStream
  Dim DESC As New DESCryptoServiceProvider
  Dim CStream As New CryptoStream(ms, DESC.CreateDecryptor(Encoding.Default.GetBytes("20000000"), Encoding.Default.GetBytes("字节数量")), CryptoStreamMode.Write)
  CStream.Write(ByteInput, 0, ByteInput.Length)
  CStream.FlushFinalBlock()
  Return Encoding.Default.GetString(ms.ToArray())  
End Function
End Class

------解决方案--------------------
大概是下面的写法即可,因为wince上的GetString方法没有只有一个参数的重载
Return Encoding.Default.GetString(ms.ToArray(),0,ms.ToArray().length)
  相关解决方案