Как зашифровать данные с помощью открытого ключа 4096 в C#
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAptpd4uLByeNpVOX5CsEi1aEldDXmxKOlarUrVSvep707QMKzBd01voyj19QobudoEc3oThA1VvZGSJPC/6D7/BDQ+uyO83tL0/zNcfLsE0xFbbNlKgoadGLZR59EHxaSD0MadiNfK4l4e2RiCrqAGQeGKv5rBd6GChtI5Yugih+CiM5k65QidF2nLxikg1212v6vrV+oxILB0wrWPLHvHjicIi7OaVRIeChitP3G90L1Tu6zwAZaw2up7vy5HHn1Uz+vlUxJFQth7S2945n82oZ3JkFKEIJJmbHEZzqWbznTdvctQ7ZXMXExZXLAme29I+Ez899Hu9zzkfb4oLA8ZVC+vYzg8Bfx+bp0f20M0ZlJQxYujI924iiCkjGr6soL+98LDZ4cXfKKzdNOiXH5WrAcmFzXz+JVBN/Tk+1YnKRQkzjUz3JZnlKSHRDft2FXI8YUlNgbPb/HEPd2cL8S61GUdYIIHIWvkhiIxNRY6svvHfuB1T7MNl4/xPLE3ilK7peu/Z/NLoSLYs8i7OD4FPConBlo9RPnWuPjf0zET2pITXq9a7OSk5yeHzoBRTfV8cuD11LzIJEvt17cqx4w0Ah8y13/UT115fj6usu3/ZJCmFlH56ng3eHYilsfwPajFsrO34JF+zimwnXAOeqzcFX5mmp2aQ65uZ51L1/Fx2MCAwEAAQ==
Что я уже пробовал:
public string EncryptByPublicKey(string data, string publicKey) { IAsymmetricBlockCipher engine = new Pkcs1Encoding(new RsaEngine()); try { RsaKeyParameters key = (RsaKeyParameters)GetPublicKeyParameter(publicKey); engine.Init(true, key); byte[] byteData = Encoding_UTF8.GetBytes(data); int maxBlock = key.Modulus.BitLength / 8 - 11; List<byte> resultData = new List<byte>(); int offSet = 0; for (int i = 0; byteData.Length > offSet; i++) { byte[] tmpByte = new byte[] { }; if (byteData.Length - offSet > maxBlock) { tmpByte = engine.ProcessBlock(byteData, offSet, maxBlock); } else { tmpByte = engine.ProcessBlock(byteData, offSet, byteData.Length - offSet); } offSet = maxBlock * (i + 1); resultData.AddRange(tmpByte); } //for (int chunkPosition = 0;chunkPosition < byteData.Length; chunkPosition += maxBlock) //{ // int chunkSize = Math.Min(maxBlock, byteData.Length - chunkPosition); // resultData.AddRange(engine.ProcessBlock( // byteData, chunkPosition, chunkSize // )); //} string cipherText = Convert.ToBase64String( Encoding.UTF8.GetBytes( Convert.ToBase64String(resultData.ToArray()))); return cipherText; } catch (Exception ex) { throw ex; } }
Richard MacCutchan
В чем же вопрос?
ZurdoDev
В чем же вопрос?
Gerry Schmitz
Почему? Для кого?