谁能帮忙把这段C#翻译nodejs版本
发布于 2 年前 作者 im-here 1975 次浏览 来自 问答

是关于rsa解密的

public static String decrypt(String cryptograph, BigInteger d,BigInteger n, int numBit)
 {
            String[] chs = cryptograph.Split(' ');
            if (chs == null || chs.GetLength(0) <= 0)
            {
                throw new Exception("密文不符合要求!!!");
            }
            int numeroToken = chs.GetLength(0);
            BigInteger[] StringToByte = new BigInteger[numeroToken];
            for (int i = 0; i < numeroToken; i++)
            {
                StringToByte[i] = new BigInteger(chs[i], 16);
            }
            byte[][] encodeM = dencodeRSA(StringToByte, d, n);
            byte[] sendMessage = StringToByte(encodeM);
            //String message = new String(sendMessage, "UTF-8");
            string message = System.Text.Encoding.Default.GetString(sendMessage);
            String result = System.Web.HttpUtility.UrlDecode(message, Encoding.UTF8);//.UrlDecode.decode(message, "UTF-8");
            return result;
        }
 private static byte[][] dencodeRSA(BigInteger[] encodeM, BigInteger d,BigInteger n)
{
            byte[][] dencodeM = new byte[encodeM.GetLength(0)][];
            int i;
            int lung = encodeM.GetLength(0);
            for (i = 0; i < lung; i++)
            {
                dencodeM[i] = encodeM[i].ModPow(d, n).ToByteArray();
            }
            return dencodeM;
        }
 private static byte[] StringToByte(byte[][] arraySenS)
{
            int i, dab = 0;
            for (i = 0; i < arraySenS.GetLength(0); i++)
            {
                if (arraySenS[i] == null)
                {
                    return null;
                }
                dab = dab + arraySenS[i].GetLength(0);
            }
            List<Byte> listByte = new List<Byte>();
            int j;
            for (i = 0; i < arraySenS.GetLength(0); i++)
            {
                for (j = 0; j < arraySenS[i].GetLength(0); j++)
                {
                    if (arraySenS[i][j] != 0x20)
                    {
                        listByte.Add(arraySenS[i][j]);
                    }
                }
            }
            Byte[] arrayByte = listByte.ToArray();//.toArray(new Byte[0]);
            byte[] result = new byte[arrayByte.GetLength(0)];
            for (int k = 0; k < arrayByte.GetLength(0); k++)
            {
                result[k] = (arrayByte[k]);//.byteValue();
            }
            listByte = null;
            arrayByte = null;
            return result;
        }
回到顶部