Skip to content
Snippets Groups Projects
Select Git revision
  • bf7d95fd989b1a6bc3cde227ed27627ad7db1e11
  • main default protected
  • gitkeep
  • dev protected
  • Issue/2914-trellisMigrator
  • Issue/2847-reporting
  • Hotfix/2776-workingNewVersion
  • Hotfix/xxxx-correctAssignments
  • Issue/2666-adminCronjobs-theSequal
  • Issue/2666-adminCronjobs
  • Issue/2518-docs
  • Hotfix/xxxx-coscineGraph
  • Issue/2304-virtuosoRoars
  • Fix/v0.1.7-dependencies
  • Hotfix/2212-fixFiles
  • Issue/2222-resourceDateCreated
  • Issue/2221-projectDateCreated
  • Hotfix/xxxx-changeUrls
  • Issue/1321-pidEnquiryOverhaul
  • Issue/1782-structualDataIntegration
  • Issue/2084-migrateResourceStructuralData
  • v0.1.24
  • v0.1.23
  • v0.1.22
  • v0.1.21
  • v0.1.20
  • v0.1.19
  • v0.1.18
  • v0.1.17
  • v0.1.16
  • v0.1.15
  • v0.1.14
  • v0.1.13
  • v0.1.12
  • v0.1.11
  • v0.1.10
  • v0.1.9
  • v0.1.7
  • v0.1.8
  • v0.1.6
  • v0.1.5
41 results

ResourceStructuralData.cs

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    RelayStateGenerator.cs 1.40 KiB
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Sustainsys.Saml2
    {
        /// <summary>
        /// Generator of secure random keys..
        /// </summary>
        static class SecureKeyGenerator
        {
            private static RNGCryptoServiceProvider random =
                new RNGCryptoServiceProvider();
    
            /// <summary>
            /// Create a unique random string with a cryptographically secure
            /// random function.
            /// </summary>
            /// <returns>Random string 56-chars string</returns>
            public static string CreateRelayState()
            {
                // 16 is considered secure, but Base64 pads 16 bytes so
                // use 18 to make it even with Base64 that encodes multiples 
                // of 3 bytes)
                var bytes = new byte[18];
                random.GetBytes(bytes);
    
                return Convert.ToBase64String(bytes)
                    .Replace('/', '-')
                    .Replace('+', '_');
            }
    
            /// <summary>
            /// Create a unique random array with a cryptographically secure
            /// random function.
            /// </summary>
            /// <returns>20 random bytes.</returns>
            public static byte[] CreateArtifactMessageHandle()
            {
                var bytes = new byte[20];
                random.GetBytes(bytes);
    
                return bytes;
            }
        }
    }