这似乎是一件很简单的事情,但我已经尝试了一个多星期,似乎找不到答案。我们正在创建一个Windows UWP应用程序使用WinJS,并希望用户登录到该应用程序与PIV (智能卡)/PIN组合。基本上,当应用程序启动时,它将验证设备中是否插入了智能卡,然后提示用户输入PIN。如果根据智能卡验证了PIN,则应用程序将使用户登录。
我们确实有Windows 7应用程序可以做到这一点,我试图转换代码,但我们使用的API似乎对Windows UWP应用程序无效。我确实发布了关于这些API的问题,但没有收到任何响应(https://stackoverflow.com/questions/43344679/x509certificate2ui-class-equivalent-with-windows-uwp-and-winjs)。在Windows7中,我们使用X509Certificate2UI (https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2ui(v=vs.110).aspx )类来选择提示用户输入PIN码的证书。
经过大量研究,我认为(可能是错误的) Windows UWP需要使用智能卡API (https://docs.microsoft.com/en-us/uwp/api/windows.devices.smartcards )。在过去的几天里,我一直在阅读智能卡上的几个微软文档,比如:https://docs.microsoft.com/en-us/windows/uwp/security/smart-cards,但没有找到一种方法来验证用户输入的个人识别码是否与智能卡上的个人识别码相符。
从SmartCardProvisioning类(https://docs.microsoft.com/en-us/uwp/api/windows.devices.smartcards.smartcardprovisioning ),我们能够调用requestPinChangeAsync()方法,该方法提示用户输入当前PIN码和新的PIN码。我正在寻找类似的功能,除了它只要求当前的个人识别码,然后返回一个值,将让应用程序知道个人识别码是否正确。
我还通读了微软的Hello (https://docs.microsoft.com/en-us/windows/uwp/security/microsoft-passport ) API,但没有看到将其与智能卡一起使用的方法。
关于如何使用智能卡/PIN组合在我的应用程序中使用双因素身份验证,有人能为我指出正确的方向吗?在过去的几天里,我似乎一直处于谷歌的泡沫之中,需要帮助才能走出来。
谢谢
编辑解释为什么它不是副本:不是真正的副本,这两个问题都是我问的,我在问题的bod中提到了另一个帖子。在另一篇文章中,我正在寻找一个等价于使用WinJS的Windows UWP的X509Certificate2UI类。随着进一步的研究,我认为这可能不是正确的方式,因此我希望在这篇文章中,是否有人可以为我指出使用PIV (智能卡)和与卡相关的PIN进行双因素身份验证的正确方向。
编辑:共享可以工作的代码:这里是似乎可以工作的WinJS代码。不确定是否有更好的方法:
if (certToUse != null) {
Windows.Security.Cryptography.Core.PersistedKeyProvider.openKeyPairFromCertificateAsync(certToUse, Windows.Security.Cryptography.Core.HashAlgorithmNames.sha256, Windows.Security.Cryptography.Core.CryptographicPadding.rsaPkcs1V15).then(function (keyPair) {
var buffer = 'data to sign'
var data = Windows.Security.Cryptography.CryptographicBuffer.convertStringToBinary(buffer, Windows.Security.Cryptography.BinaryStringEncoding.utf16BE)
Windows.Security.Cryptography.Core.CryptographicEngine.signAsync(keyPair, data).then(function (signed) {
var results = Windows.Security.Cryptography.Core.CryptographicEngine.verifySignature(keyPair, data, signed)
completeValidatePin = true
successCallback(true)
}, function (reason) {
completeValidatePin = true
errorCallback('User cancelled login')
})
}, function (reason) {
completeValidatePin = true
errorCallback('Error using certificate')
})
} else {
errorCallback('Certificate not found')
}发布于 2017-05-02 02:56:23
我目前正在调查你的问题,并试图确定是否有一个好的解决方案。
我确实写了下面的代码,我认为它应该可以工作:
IReadOnlyList<Certificate> Certs;
CertificateQuery CertQuery = new CertificateQuery();
CertQuery.HardwareOnly = true;
Certs = await CertificateStores.FindAllAsync(CertQuery);
string strEncrypt = "test";
IBuffer BufferToEncrypt = CryptographicBuffer.ConvertStringToBinary(strEncrypt, BinaryStringEncoding.Utf8);
foreach (Certificate Cert in Certs)
{
if (Cert.HasPrivateKey && ((Cert.KeyStorageProviderName == "Microsoft Base Smart Card Crypto Provider") || Cert.KeyStorageProviderName == "Microsoft Smart Card Key Storage Provider"))
{
CryptographicKey Key = null;
try
{
Key = await PersistedKeyProvider.OpenKeyPairFromCertificateAsync(Cert, HashAlgorithmNames.Sha1, CryptographicPadding.RsaPkcs1V15);
}
catch (Exception ex)
{
// Could not open Smart Card Key Pair
}
if (Key != null)
{
try
{
// Try to Sign with Cert Private key
IBuffer EncryptedBuffer = CryptographicEngine.Sign(Key, BufferToEncrypt);
}
catch (Exception ex)
{
// Could not sign
}
}
}
}不幸的是,PIN码创建了一个具有静默上下文的提供程序,因此CryptographicEngine.Sign无法显示OpenKeyPairFromCertificateAsync对话框。我将不得不更深入地研究它。
https://stackoverflow.com/questions/43373052
复制相似问题