SebWindowsClient.ConfigurationUtils.SEBConfigFileManager.DecryptDataWithPublicKeyHashPrefix C# (CSharp) Method

DecryptDataWithPublicKeyHashPrefix() private static method

Helper method which fetches the public key hash from a byte array, retrieves the according cryptographic identity from the certificate store and returns the decrypted bytes
private static DecryptDataWithPublicKeyHashPrefix ( byte sebData, bool forEditing, X509Certificate2 &sebFileCertificateRef ) : byte[]
sebData byte
forEditing bool
sebFileCertificateRef System.Security.Cryptography.X509Certificates.X509Certificate2
return byte[]
        private static byte[] DecryptDataWithPublicKeyHashPrefix(byte[] sebData, bool forEditing, ref X509Certificate2 sebFileCertificateRef)
        {
            // Get 20 bytes public key hash prefix
            // and remaining data with the prefix stripped
            byte[] publicKeyHash = GetPrefixDataFromData(ref sebData, PUBLIC_KEY_HASH_LENGTH);

            X509Certificate2 certificateRef = SEBProtectionController.GetCertificateFromStore(publicKeyHash);
            if (certificateRef == null)
            {
                SEBMessageBox.Show(SEBUIStrings.errorDecryptingSettings, SEBUIStrings.certificateNotFoundInStore, MessageBoxIcon.Error, MessageBoxButtons.OK, neverShowTouchOptimized: forEditing);
                return null;
            }
            // If these settings are being decrypted for editing, we will return the decryption certificate reference
            // in the variable which was passed as reference when calling this method
            if (forEditing) sebFileCertificateRef = certificateRef;

            sebData = SEBProtectionController.DecryptDataWithCertificate(sebData, certificateRef);

            return sebData;
        }

Usage Example

        public static Dictionary <string, object> DecryptSEBSettings(byte[] sebData, bool forEditing, ref string sebFilePassword, ref bool passwordIsHash, ref X509Certificate2 sebFileCertificateRef)
        {
            byte[] numArray1 = GZipByte.Decompress(sebData);
            if (numArray1 != null)
            {
                sebData = numArray1;
            }
            byte[] numArray2            = sebData.Clone() as byte[];
            string prefixStringFromData = SEBConfigFileManager.GetPrefixStringFromData(ref sebData);

            if (prefixStringFromData.CompareTo("pkhs") == 0)
            {
                sebData = SEBConfigFileManager.DecryptDataWithPublicKeyHashPrefix(sebData, forEditing, ref sebFileCertificateRef);
                if (sebData == null)
                {
                    return((Dictionary <string, object>)null);
                }
                prefixStringFromData = SEBConfigFileManager.GetPrefixStringFromData(ref sebData);
            }
            if (prefixStringFromData.CompareTo("pswd") == 0)
            {
                string passwordRequestText = SEBUIStrings.enterPassword;
                int    num1 = 5;
                string passphrase;
                byte[] numArray3;
                do
                {
                    --num1;
                    passphrase = ThreadedDialog.ShowPasswordDialogForm(SEBUIStrings.loadingSettings, passwordRequestText);
                    if (passphrase == null)
                    {
                        return((Dictionary <string, object>)null);
                    }
                    numArray3           = SEBProtectionController.DecryptDataWithPassword(sebData, passphrase);
                    passwordRequestText = SEBUIStrings.enterPasswordAgain;
                }while (numArray3 == null && num1 > 0);
                if (numArray3 == null)
                {
                    int num2 = (int)SEBMessageBox.Show(SEBUIStrings.decryptingSettingsFailed, SEBUIStrings.decryptingSettingsFailedReason, MessageBoxIcon.Hand, MessageBoxButtons.OK, forEditing);
                    return((Dictionary <string, object>)null);
                }
                sebData = numArray3;
                if (forEditing)
                {
                    sebFilePassword = passphrase;
                }
            }
            else
            {
                if (prefixStringFromData.CompareTo("pwcc") == 0)
                {
                    return(SEBConfigFileManager.DecryptDataWithPasswordForConfiguringClient(sebData, forEditing, ref sebFilePassword, ref passwordIsHash));
                }
                if (prefixStringFromData.CompareTo("plnd") != 0)
                {
                    if (prefixStringFromData.CompareTo("<?xm") == 0)
                    {
                        sebData = numArray2;
                    }
                    else
                    {
                        int num = (int)SEBMessageBox.Show(SEBUIStrings.settingsNotUsable, SEBUIStrings.settingsNotUsableReason, MessageBoxIcon.Hand, MessageBoxButtons.OK, forEditing);
                        return((Dictionary <string, object>)null);
                    }
                }
            }
            if (prefixStringFromData.CompareTo("<?xm") != 0)
            {
                sebData = GZipByte.Decompress(sebData);
            }
            Dictionary <string, object> dictFromConfigData = SEBConfigFileManager.GetPreferencesDictFromConfigData(sebData, forEditing);

            if (dictFromConfigData == null)
            {
                return((Dictionary <string, object>)null);
            }
            dictFromConfigData["sebConfigPurpose"] = (object)0;
            return(dictFromConfigData);
        }