public AlgorithmRsa(int bits, string modulus, string exponent) { try { _nBits = bits; var xx = Convert.FromBase64String(exponent); _pExponent = new BigIntegerFixed(Convert.FromBase64String(exponent)); _pModulus = new BigIntegerFixed(Convert.FromBase64String(modulus)); } catch (Exception ex) { throw new ArgumentException("Missed data for RSA algorithm", ex); } }
public byte[] Encrypt(byte[] data, bool isPadding = true) { var toEncrypt = data; if (isPadding) { toEncrypt = AddPadding(data, _nBits); } var src = new BigIntegerFixed(toEncrypt); var res = src.ModPow(_pExponent, _pModulus); var bytesResult = res.getBytes(); if (!isPadding) { //need to remove padding bytesResult = RemovePadding(bytesResult); } return(bytesResult); }