private bool DeletePasswordImpl(string credentialId) { // Find password, then Delete, then cleanup using (KeyChainItemHandle handle = LookupKeyChainItem(credentialId)) { if (handle == null) { return(false); } Interop.Security.OSStatus status = Interop.Security.SecKeychainItemDelete(handle); return(status == Interop.Security.OSStatus.ErrSecSuccess); } }
private bool AddGenericPassword(Credential credential) { IntPtr passwordPtr = Marshal.StringToCoTaskMemUni(credential.Password); Interop.Security.OSStatus status = Interop.Security.SecKeychainAddGenericPassword( IntPtr.Zero, InteropUtils.GetLengthInBytes(credential.CredentialId), credential.CredentialId, 0, null, InteropUtils.GetLengthInBytes(credential.Password), passwordPtr, IntPtr.Zero); return(status == Interop.Security.OSStatus.ErrSecSuccess); }
private KeyChainItemHandle LookupKeyChainItem(string credentialId) { UInt32 passwordLength; IntPtr passwordPtr; IntPtr item; Interop.Security.OSStatus status = Interop.Security.SecKeychainFindGenericPassword( IntPtr.Zero, InteropUtils.GetLengthInBytes(credentialId), credentialId, 0, null, out passwordLength, out passwordPtr, out item); if (status == Interop.Security.OSStatus.ErrSecSuccess) { return(new KeyChainItemHandle(item, passwordPtr, passwordLength)); } return(null); }