Пример #1
0
        public string EncodeData(string data)
        {
            if (!hasPublicKeys)
            {
                throw new NotSupportedException("You need to load keys first");
            }

            var rsa = new RsaEncryptor(_encpubkeyN, _encpubkeyE);
            var encString = Convert.ToBase64String(_encoding.GetBytes(data));
            var num = (double)encString.Length / 245;
            var resTotal = string.Empty;
            for (int i = 0; i < num; i++)
            {
                var index = i * 245;
                var length = 245;
                if (index + 245 > encString.Length)
                {
                    length = encString.Length - index;
                }
                var encData = encString.Substring(index, length);
                var res = rsa.EncryptData(encData);
                resTotal += res;
            }
            return resTotal;
        }