Пример #1
0
        public static byte[] RSA2048Decrypt(byte[] ciphertext, RSAKeyset keyset)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

            rsa.ImportParameters(new RSAParameters
            {
                P        = keyset.Prime1,
                Q        = keyset.Prime2,
                Exponent = keyset.PublicExponent,
                Modulus  = keyset.Modulus,
                DP       = keyset.Exponent1,
                DQ       = keyset.Exponent2,
                InverseQ = keyset.Coefficient,
                D        = keyset.PrivateExponent
            });
            return(rsa.Decrypt(ciphertext, false));
        }
Пример #2
0
        /// <summary>
        /// Sign the given SHA-256 hash with PKCS1 padding
        /// </summary>
        /// <param name="sha256Hash">Hash</param>
        /// <param name="keyset">Keys to use</param>
        /// <returns>RSA 2048 signature of the hash</returns>
        public static byte[] RSA2048SignSha256(byte[] sha256Hash, RSAKeyset keyset)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

            rsa.ImportParameters(new RSAParameters
            {
                P        = keyset.Prime1,
                Q        = keyset.Prime2,
                Exponent = keyset.PublicExponent,
                Modulus  = keyset.Modulus,
                DP       = keyset.Exponent1,
                DQ       = keyset.Exponent2,
                InverseQ = keyset.Coefficient,
                D        = keyset.PrivateExponent
            });
            return(rsa.SignHash(sha256Hash, CryptoConfig.MapNameToOID("SHA256")));
        }
Пример #3
0
        /// <summary>
        /// From FPKG Code (sceSblPfsSetKeys): Turns the EEKPfs to an EKPfs
        /// </summary>
        public static byte[] DecryptEEKPfs(byte[] eekpfs, RSAKeyset keyset)
        {
            var @params = new RSAParameters
            {
                D        = keyset.PrivateExponent,
                DP       = keyset.Exponent1,
                DQ       = keyset.Exponent2,
                Exponent = keyset.PublicExponent,
                InverseQ = keyset.Coefficient,
                Modulus  = keyset.Modulus,
                P        = keyset.Prime1,
                Q        = keyset.Prime2
            };

            using (var rsa = RSA.Create())
            {
                rsa.KeySize = 2048;
                rsa.ImportParameters(@params);
                return(rsa.DecryptValue(eekpfs));
            }
        }