/// <summary>
        /// Gets the KRB-CRED Kerberos Ticket information as byte stream.
        /// </summary>
        /// <param name="ticket">Kerberos ticket object to save.</param>
        /// <returns>Byte stream representaion of KRB-CRED Kerberos Ticket if it contains valid ticket information.
        /// Null, otherwise.</returns>
        public static byte[] GetKrbCred(KerberosSupplementalTicket ticket)
        {
            if (!string.IsNullOrEmpty(ticket.KerberosMessageBuffer))
            {
                return(Convert.FromBase64String(ticket.KerberosMessageBuffer));
            }

            return(null);
        }
        /// <summary>
        /// Save current Kerberos Ticket to current user's Ticket Cache. Windows only.
        /// </summary>
        /// <param name="ticket">Kerberos ticket object to save.</param>
        /// <param name="logonId">The Logon Id of the user owning the ticket cache.
        /// The default of 0 represents the currently logged on user.</param>
        /// <remarks>Can throw <see cref="ArgumentException"/> when given ticket parameter is not a valid Kerberos Supplemental Ticket.
        /// Can throw <see cref="Win32Exception"/> if error occurs while saving ticket information into Ticket Cache.
        /// </remarks>
        public static void SaveToWindowsTicketCache(KerberosSupplementalTicket ticket, long logonId)
        {
#if !SUPPORTS_WIN32
            throw new PlatformNotSupportedException("Ticket Cache interface is not supported for this .NET platform. It is supported on .NET Classic, .NET Core and NetStandadrd");
#else
            if (!DesktopOsHelper.IsWindows())
            {
                throw new PlatformNotSupportedException("Ticket Cache interface is not supported on this OS. It is supported on Windows only.");
            }

            if (ticket == null || string.IsNullOrEmpty(ticket.KerberosMessageBuffer))
            {
                throw new ArgumentException("Kerberos Ticket information is not valid");
            }

            using (var cache = Platforms.Features.DesktopOs.Kerberos.TicketCacheWriter.Connect())
            {
                byte[] krbCred = Convert.FromBase64String(ticket.KerberosMessageBuffer);
                cache.ImportCredential(krbCred, logonId);
            }
#endif
        }
 /// <summary>
 /// Save current Kerberos Ticket to current user's Ticket Cache.
 /// </summary>
 /// <param name="ticket">Kerberos ticket object to save.</param>
 /// <remarks>Can throws <see cref="ArgumentException"/> when given ticket parameter is not a valid Kerberos Supplemental Ticket.
 /// Can throws <see cref="Win32Exception"/> if error occurs while saving ticket information into Ticket Cache.
 /// </remarks>
 public static void SaveToWindowsTicketCache(KerberosSupplementalTicket ticket)
 {
     SaveToWindowsTicketCache(ticket, DefaultLogonId);
 }