兰姆达表达式 C#代码 用VB代码疑问

array as sbyte()=new sbyte() { -84 , 99 , -7 }
c#.NET代码:
System.Array.ConvertAll<sbyte, byte>(array, a => (byte) a)
VB.NET代码:
System.Array.ConvertAll(Of SByte, Byte)(array, Function(a) (IIf(a > 0, a, 256 - Math.Abs(a))))
array参数是定义好的sbyte()
套嵌 iif(a>0,cbyte(a),cbyte(256-Math.Abs(a))) 时候出错,array数组里面有负数
把cbyte 壳去掉竟然好了
VB.NET里面没有更好的转换方法么?将SBbyte转换Byte

【VB.NET完整过程代码】
    Public Shared Function DecryptionKEY(ByVal message As String) As String
        Try
            Dim keystring As String = "q1!2@3#we>WacE/.Q,?<b"
            Dim array As SByte() = New SByte() {-87, -101, -56, 50, &H56, &H35, -29, 3}
            Dim num As Integer = &H13
            Dim generator As New PKCSKeyGenerator(keystring, System.Array.ConvertAll(Of SByte, Byte)(array, Function(a) (IIf(a > 0, a, 256 - Math.Abs(a)))), num, 1)
            Dim inputBuffer As Byte() = Convert.FromBase64String(message)
            Dim bytes As Byte() = generator.Decryptor.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length)
            Return Encoding.UTF8.GetString(bytes)
        Catch ex As Exception
            Return "ERROR CODE 702"
        End Try
    End Function
【C#完整代码】
public static String DecryptionKEY(String message)
        {
            try
            {
                String key = "q1!2@3#we>WacE/.Q,?<b";  
                sbyte[] salt = { -87, -101, -56, 50, 86, 53, -29, 3 }; 
                int count = 19; 


                PKCSKeyGenerator cipher = new PKCSKeyGenerator(key, Array.ConvertAll(salt, a => (byte)a), count, 1);
                byte[] src = Convert.FromBase64String(message);
                byte[] result = cipher.Decryptor.TransformFinalBlock(src, 0, src.Length);
                return Encoding.UTF8.GetString(result);
            }
            catch
            {
                return "DecryptionKEY Fail.";
            }
            
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值