private static string MD5(string text, bool useEasyScope16)
        {
            var result = default(string);

            using (var algo = new MD5CryptoServiceProvider())
            {
                algo.ComputeHash(Encoding.UTF8.GetBytes(text));
                result = CU.ToHexString(algo.Hash);
            }
            return(result.Substring(0, useEasyScope16?16:8));
        }
예제 #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Creates rsa keys and a RSA provider. </summary>
        ///
        /// <remarks>   Chris, 4/2/2020. </remarks>
        ///
        /// <param name="RSAKey">               [out] The rsa key. </param>
        /// <param name="RSAPublic">            [out] The rsa public. </param>
        /// <param name="createXMLKeyAlways">   (Optional) True to create XML key always. </param>
        ///
        /// <returns>   The new rsa keys. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public RSACryptoServiceProvider CreateRSAKeys(out string RSAKey, out string RSAPublic, bool createXMLKeyAlways = false)
        {
            RSACryptoServiceProvider rsa;

            RSAKey = null;
            if (Environment.OSVersion.Platform == PlatformID.Unix) // CODE REVIEW: Is this really the right check/condition? CM: Better would be to find out if we create this in SW or HW
            {
                rsa = new RSACryptoServiceProvider(512);
            }
            else
            {
                rsa = new RSACryptoServiceProvider();
            }
            if (!_platformDoesNotSupportRSAXMLExportImport)
            {
                try
                {
                    // TODO Decide if we want to switch to MyRSA object for the private key in general, or just for Std/Core
                    RSAKey = rsa.ToXmlString(true);
                }
                catch (PlatformNotSupportedException)
                {
                    _platformDoesNotSupportRSAXMLExportImport = true;
                }
            }
            if (_platformDoesNotSupportRSAXMLExportImport)
            {
                if (!createXMLKeyAlways)
                {
                    RSAKey = "no private key in string format on this platform";
                }
                else
                {
                    RSAKey = GetRSAKeyAsXML(rsa, true);
                }
            }
            RSAParameters param = rsa.ExportParameters(false);

            RSAPublic = CU.ToHexString(param.Exponent) + "," + CU.ToHexString(param.Modulus);
            return(rsa);
        }