Decrypt() public static method

Decrypts specified ciphertext using Rijndael symmetric key algorithm.
Most of the logic in this function is similar to the Encrypt logic. In order for decryption to work, all parameters of this function - except cipherText value - must match the corresponding parameters of the Encrypt function which was called to generate the ciphertext.
public static Decrypt ( string cipherText ) : string
cipherText string /// Base64-formatted ciphertext value. ///
return string
Esempio n. 1
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            if (File.Exists(ServerSecurityService.FileName))
            {
                string encryptedData;
                using (var inStream = new FileStream(ServerSecurityService.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (var reader = new StreamReader(inStream))
                    {
                        encryptedData = reader.ReadToEnd();
                    }
                }

                try
                {
                    var decryptData = SecurityEncryption.Decrypt(encryptedData);
                    var currentSecuritySettingsTo = JsonConvert.DeserializeObject <SecuritySettingsTO>(decryptData);
                    var permissionGroup           = currentSecuritySettingsTo.WindowsGroupPermissions;

                    // We need to change BuiltIn\Administrators to -> Warewolf Administrators ;)
                    if (permissionGroup.Count > 0)
                    {
                        var adminGrp = permissionGroup[0].WindowsGroup;
                        if (adminGrp == "BuiltIn\\Administrators")
                        {
                            permissionGroup[0].WindowsGroup = WindowsGroupPermission.BuiltInAdministratorsText;
                            decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                        }
                    }

                    var hasGuestPermission = permissionGroup.Any(permission => permission.IsBuiltInGuests);
                    var hasAdminPermission = permissionGroup.Any(permission => permission.IsBuiltInAdministrators);
                    if (!hasAdminPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateAdministrators());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    if (!hasGuestPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateGuests());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    return(new StringBuilder(decryptData));
                }
                catch (Exception e)
                {
                    Dev2Logger.Log.Error("SecurityRead", e);
                }
            }

            var serializer         = new Dev2JsonSerializer();
            var securitySettingsTo = new SecuritySettingsTO(DefaultPermissions)
            {
                CacheTimeout = _cacheTimeout
            };

            return(serializer.SerializeToBuilder(securitySettingsTo));
        }
Esempio n. 2
0
        StringBuilder Execute(string encryptedData)
        {
            var decryptData = SecurityEncryption.Decrypt(encryptedData);

            Dev2Logger.Debug(decryptData, GlobalConstants.WarewolfDebug);
            var currentSecuritySettingsTo = JsonConvert.DeserializeObject <SecuritySettingsTO>(decryptData);

            if (currentSecuritySettingsTo.WindowsGroupPermissions.Any(a => a.ResourceID != Guid.Empty))
            {
                foreach (var perm in currentSecuritySettingsTo.WindowsGroupPermissions.Where(a => a.ResourceID != Guid.Empty))
                {
                    perm.ResourceName = Catalog.GetResourcePath(GlobalConstants.ServerWorkspaceID, perm.ResourceID);
                }
            }
            decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
            var permissionGroup = currentSecuritySettingsTo.WindowsGroupPermissions;

            // We need to change BuiltIn\Administrators to -> Warewolf Administrators ;)
            if (permissionGroup.Count > 0)
            {
                var adminGrp = permissionGroup[0].WindowsGroup;
                if (adminGrp == "BuiltIn\\Administrators")
                {
                    permissionGroup[0].WindowsGroup = WindowsGroupPermission.BuiltInAdministratorsText;
                    decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                }
            }

            var hasGuestPermission = permissionGroup.Any(permission => permission.IsBuiltInGuests);
            var hasAdminPermission = permissionGroup.Any(permission => permission.IsBuiltInAdministrators);

            if (!hasAdminPermission)
            {
                permissionGroup.Add(WindowsGroupPermission.CreateAdministrators());
                permissionGroup.Sort(QuickSortForPermissions);
                decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
            }
            if (!hasGuestPermission)
            {
                permissionGroup.Add(WindowsGroupPermission.CreateGuests());
                permissionGroup.Sort(QuickSortForPermissions);
                decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
            }
            return(new StringBuilder(decryptData));
        }
Esempio n. 3
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            Dev2Logger.Debug("Start Security Read");
            var serverSecuritySettingsFile = EnvironmentVariables.ServerSecuritySettingsFile;

            if (File.Exists(serverSecuritySettingsFile))
            {
                string encryptedData;
                using (var inStream = new FileStream(serverSecuritySettingsFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (var reader = new StreamReader(inStream))
                    {
                        encryptedData = reader.ReadToEnd();
                    }
                }
                Dev2Logger.Debug("Security Data Read");
                try
                {
                    var decryptData = SecurityEncryption.Decrypt(encryptedData);
                    Dev2Logger.Debug(decryptData);
                    var currentSecuritySettingsTo = JsonConvert.DeserializeObject <SecuritySettingsTO>(decryptData);
                    if (currentSecuritySettingsTo.WindowsGroupPermissions.Any(a => a.ResourceID != Guid.Empty))
                    {
                        foreach (var perm in currentSecuritySettingsTo.WindowsGroupPermissions.Where(a => a.ResourceID != Guid.Empty))
                        {
                            perm.ResourceName = Catalog.GetResourcePath(GlobalConstants.ServerWorkspaceID, perm.ResourceID);
                        }
                    }
                    decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    var permissionGroup = currentSecuritySettingsTo.WindowsGroupPermissions;

                    // We need to change BuiltIn\Administrators to -> Warewolf Administrators ;)
                    if (permissionGroup.Count > 0)
                    {
                        var adminGrp = permissionGroup[0].WindowsGroup;
                        if (adminGrp == "BuiltIn\\Administrators")
                        {
                            permissionGroup[0].WindowsGroup = WindowsGroupPermission.BuiltInAdministratorsText;
                            decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                        }
                    }

                    var hasGuestPermission = permissionGroup.Any(permission => permission.IsBuiltInGuests);
                    var hasAdminPermission = permissionGroup.Any(permission => permission.IsBuiltInAdministrators);
                    if (!hasAdminPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateAdministrators());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    if (!hasGuestPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateGuests());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    return(new StringBuilder(decryptData));
                }
                catch (Exception e)
                {
                    Dev2Logger.Error("SecurityRead", e);
                }
            }

            var serializer         = new Dev2JsonSerializer();
            var securitySettingsTo = new SecuritySettingsTO(DefaultPermissions)
            {
                CacheTimeout = _cacheTimeout
            };

            return(serializer.SerializeToBuilder(securitySettingsTo));
        }