public RSAConfig(byte[] modulus, byte[] exponent, int modulusSize) { _ModulusOctets = modulusSize / 8; _E = RSAHelper.OS2IP(exponent, false); _N = RSAHelper.OS2IP(modulus, false); _Has_PUBLIC_Info = true; }
public byte[] CrunchRSA(byte[] plainText, bool usePrivate) { if (usePrivate && (!_rsaConfig.Has_PRIVATE_Info)) { throw new CryptographicException("No private key"); } if ((usePrivate == false) && (!_rsaConfig.Has_PUBLIC_Info)) { throw new CryptographicException("No public key"); } BigInteger e; if (usePrivate) { e = _rsaConfig.D; } else { e = _rsaConfig.E; } var PT = RSAHelper.OS2IP(plainText, false); var M = BigInteger.ModPow(PT, e, _rsaConfig.N); return(M.Sign == -1 ? RSAHelper.I2OSP(M + _rsaConfig.N, _rsaConfig.OctetsInModulus, false) : RSAHelper.I2OSP(M, _rsaConfig.OctetsInModulus, false)); }
public RSAConfig(byte[] modulus, byte[] exponent, byte[] d, int modulusSize) { // _rsaConfig; _ModulusOctets = modulusSize / 8; _E = RSAHelper.OS2IP(exponent, false); _N = RSAHelper.OS2IP(modulus, false); _D = RSAHelper.OS2IP(d, false); _Has_PUBLIC_Info = true; _Has_PRIVATE_Info = true; }
public RSAConfig(byte[] modulus, byte[] exponent, byte[] d, byte[] P, byte[] Q, byte[] DP, byte[] DQ, byte[] inverseQ, int modulusSize) { _ModulusOctets = modulusSize / 8; _E = RSAHelper.OS2IP(exponent, false); _N = RSAHelper.OS2IP(modulus, false); _D = RSAHelper.OS2IP(d, false); _P = RSAHelper.OS2IP(P, false); _Q = RSAHelper.OS2IP(Q, false); _DP = RSAHelper.OS2IP(DP, false); _DQ = RSAHelper.OS2IP(DQ, false); _InverseQ = RSAHelper.OS2IP(inverseQ, false); _Has_CRT_Info = true; _Has_PUBLIC_Info = true; _Has_PRIVATE_Info = true; }
public RSAConfig(RSAParameters rsaParams, int ModulusSize) { _ModulusOctets = ModulusSize / 8; _E = RSAHelper.OS2IP(rsaParams.Exponent, false); _D = RSAHelper.OS2IP(rsaParams.D, false); _N = RSAHelper.OS2IP(rsaParams.Modulus, false); _P = RSAHelper.OS2IP(rsaParams.P, false); _Q = RSAHelper.OS2IP(rsaParams.Q, false); _DP = RSAHelper.OS2IP(rsaParams.DP, false); _DQ = RSAHelper.OS2IP(rsaParams.DQ, false); _InverseQ = RSAHelper.OS2IP(rsaParams.InverseQ, false); _Has_CRT_Info = true; _Has_PUBLIC_Info = true; _Has_PRIVATE_Info = true; }
public byte[] PrivateDecryptFast(byte[] data) { if (!_rsaConfig.Has_PRIVATE_Info || !_rsaConfig.HasCRTInfo) { throw new CryptographicException("No private key"); } else { var c = RSAHelper.OS2IP(data, false); var m1 = BigInteger.ModPow(c, _rsaConfig.DP, _rsaConfig.P); var m2 = BigInteger.ModPow(c, _rsaConfig.DQ, _rsaConfig.Q); var h = ((m1 - m2) * _rsaConfig.InverseQ) % _rsaConfig.P; var m = (m2 + (_rsaConfig.Q * h)); return(m.Sign == -1 ? RSAHelper.I2OSP(m + _rsaConfig.N, _rsaConfig.OctetsInModulus, false) : RSAHelper.I2OSP(m, _rsaConfig.OctetsInModulus, false)); } }