gpt4 book ai didi

xamarin.ios - 使用 Monotouch 存储和读取钥匙串(keychain)的密码

转载 作者:行者123 更新时间:2023-12-04 12:24:45 24 4
gpt4 key购买 nike

编辑:问题已解决 .为了对社区有所贡献,我在我的博客上设置了一些辅助方法和一个如何使用它们的示例。在这里找到它KeyChain MT example

--
原始问题:

在模拟器和 iPad 上运行 iOS4.2。

我正在尝试使用下面的代码从钥匙串(keychain)中存储和读取密码。我的代码灵感是https://github.com/ldandersen/scifihifi-iphone/但我无法让它工作。我错过了什么?

// Create a record.
SecRecord o = new SecRecord ( SecKind.GenericPassword );
o.Service = "myService";
o.Label = "myService";
o.Account = "test@test.com";
// The super secret password.
o.Generic = NSData.FromString ( "secret!", NSStringEncoding.UTF8 );
// Add to keychain.
SecKeyChain.Add ( o );

// Now cerate another recored to query what we just saved.
o = new SecRecord ( SecKind.GenericPassword );
o.Service = "myService";
o.Account = "test@test.com";

// Query as record.
SecStatusCode code;
var data = SecKeyChain.QueryAsRecord ( o, out code );

// This will tell us "all good!"...
Console.WriteLine ( code );

// But data.Generic is NULL and this line will crash. :-(
Console.WriteLine ( NSString.FromData ( data.Generic, NSStringEncoding.UTF8 ) );

最佳答案

而不是使用SecRecord.ValueData试试这个:

Console.WriteLine(NSString.FromData(data.Generic, NSStringEncoding.ASCIIStringEncoding));
GenericSecKind.GenericPassword 返回 NSData的被存储。

关于xamarin.ios - 使用 Monotouch 存储和读取钥匙串(keychain)的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4852108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com