コード例 #1
0
        public override string this [string key] {
            get {
                byte[] pw;
                var    status = SecKeyChain.FindGenericPassword(ApplicationName, key, out pw);
                switch (status)
                {
                case SecStatusCode.Success:
                    return(Encoding.UTF8.GetString(pw));

                case SecStatusCode.ItemNotFound:
                    return(null);

                default:
                    status.AndThrowExceptionOnFailure();
                    return(null);
                }
            }
            set {
                if (Contains(key))
                {
                    Remove(key);
                }

                Add(key, value);
            }
        }
コード例 #2
0
ファイル: TokenStore.cs プロジェクト: whjvenyl/FigmaSharp
        public string GetToken()
        {
            byte[] password_bytes;

            SecStatusCode result = SecKeyChain.FindGenericPassword(
                SERVICE, ACCOUNT, out password_bytes);

            if (result != SecStatusCode.Success)
            {
                throw new Exception("Could not find token in Keychain");
            }

            return(Encoding.UTF8.GetString(password_bytes));
        }
コード例 #3
0
        public static string GetCredentialFromFromKeychain(string username)
        {
            byte[] passwordBytes;

            if (SecKeyChain.FindGenericPassword(ServiceName, username, out passwordBytes) != SecStatusCode.Success)
            {
                return(null);
            }

            if (passwordBytes == null || passwordBytes.Length == 0)
            {
                return(null);
            }

            return(Encoding.UTF8.GetString(passwordBytes));
        }
コード例 #4
0
        public override bool Contains(string key)
        {
            byte[] pw;
            var    status = SecKeyChain.FindGenericPassword(ApplicationName, key, out pw);

            switch (status)
            {
            case SecStatusCode.Success:
                return(true);

            case SecStatusCode.ItemNotFound:
                return(false);

            default:
                status.AndThrowExceptionOnFailure();
                return(false);
            }
        }
コード例 #5
0
        public static void SaveCredentialToKeychain(string username, string password)
        {
            SecStatusCode code = SecStatusCode.NotAvailable;

            byte[] passwordBytes;

            code = SecKeyChain.FindGenericPassword(ServiceName, username, out passwordBytes);
            if (code == SecStatusCode.Success)
            {
                code = SecKeyChain.Update(new SecRecord(SecKind.GenericPassword)
                {
                    Service = ServiceName,
                    Account = username
                }, new SecRecord(SecKind.GenericPassword)
                {
                    Account   = username,
                    ValueData = NSData.FromString(password)
                });
            }
            else
            {
                code = SecKeyChain.AddGenericPassword(ServiceName, username, System.Text.Encoding.UTF8.GetBytes(password));
            }
        }