Java 安全 - MSCAPI 提供程序:如何在不弹出密码的情况下使用?

Java security - MSCAPI provider: How to use without password popup?(Java 安全 - MSCAPI 提供程序:如何在不弹出密码的情况下使用?)
本文介绍了Java 安全 - MSCAPI 提供程序:如何在不弹出密码的情况下使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经设法使用 Sun 的 MSCAPI提供者 在我的应用程序中.我现在遇到的问题是它总是弹出一个窗口,要求输入密码,即使我已经在代码中提供了密码.这是个问题,因为我需要 web 服务中的加密功能.

I've managed to use Sun's MSCAPI provider in my application. The problem I'm having now is that it always pops up a window, asking for a password, even though I've provided it in the code. This is a problem, because I need the cryptography functionality in a webservice.

这是我现在拥有的代码:

Here's the code I have now:

String alias = "Alias to my PK";
char[] pass = "MyPassword".toCharArray();

KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, pass);
Provider p =  ks.getProvider();

Signature sig = Signature.getInstance("SHA1withRSA",p);
PrivateKey key = (PrivateKey) ks.getKey(alias, pass)

sig.initSign(key);
sig.update("Testing".getBytes());
sig.sign();

这很好用,但是当最后一行运行时,我会弹出一个询问密码的窗口.我该如何预防?

This is working great, but I get a popup asking for the password when the last line is run. How do I prevent that?

推荐答案

MSCAPI提供者不支持向CAPI提供密码:

The MSCAPI provider does not support providing the password to CAPI:

假定必须提供密码的应用程序支持兼容模式.它允许(但忽略)非空密码.该模式默认启用.(1)

A compatibility mode is supported for applications that assume a password must be supplied. It permits (but ignores) a non-null password. The mode is enabled by default. (1)

要通过CAPI设置密码,必须调用CryptSetKeyParam 使用未记录的 KP_KEYEXCHANGE_PIN 或 KP_SIGNATURE_PIN 并希望您的底层硬件令牌提供商支持它.(它们并非完全没有文档 - Windows CE 和 Windows Mobile 的文档提到了它们 (2) 并且它们包含在头文件中).

To set the password through CAPI, you must call CryptSetKeyParam with the undocumented KP_KEYEXCHANGE_PIN or KP_SIGNATURE_PIN and hope your underlying hardware token provider supports it. (They are not completely undocumented - the documentation for Windows CE and Windows Mobile mention them (2) and they are included in the header files).

这篇关于Java 安全 - MSCAPI 提供程序:如何在不弹出密码的情况下使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Reliable implementation of PBKDF2-HMAC-SHA256 for JAVA(PBKDF2-HMAC-SHA256 for JAVA 的可靠实现)
Correct way to sign and verify signature using bouncycastle(使用 bouncycastle 签名和验证签名的正确方法)
Creating RSA Public Key From String(从字符串创建 RSA 公钥)
Why java.security.NoSuchProviderException No such provider: BC?(为什么 java.security.NoSuchProviderException 没有这样的提供者:BC?)
Generating X509 Certificate using Bouncy Castle Java(使用 Bouncy Castle Java 生成 X509 证书)
How can I get a PublicKey object from EC public key bytes?(如何从 EC 公钥字节中获取 PublicKey 对象?)