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 提供程序:如何在不弹出密码的情况下使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)