我想用gwt开发一个插件。它必须使用java.security。*来生成客户端密钥。 我已经提出了所有要求 但它显示以下错误。
加载模块
coreservlets.GwtApp1
Loading inherited module 'coreservlets.GwtApp1' Loading inherited module 'java.security.KeyPair' [ERROR] Unable to find 'java/security/KeyPair.gwt.xml' on your classpath; >could be a typo, or maybe you forgot to include a classpath entry for source? [ERROR] Line 15: Unexpected exception while processing element 'inherits'
我在gwtapp1.gwt.xml文件中继承了所有相关的类,如“java.security.KeyPair”
我也在classpath本身包含了jar。但是错误还没有消失。 我该怎么办.plz建议 这是我的java代码
package coreservlets.client;
import java.io.UnsupportedEncodingException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
public class Keygen {
private PrivateKey privKey;
private PublicKey pubKey;
private static Keygen keygen = null;
private Keygen() {
}
public static Keygen getInstance() {
if (keygen == null) {
keygen = new Keygen();
}
return keygen;
}
public void KeyGenerator(String ALGORITHAM) {
KeyPairGenerator keyGen = null;
SecureRandom random = null;
try {
keyGen = KeyPairGenerator.getInstance(ALGORITHAM);
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
try {
random = SecureRandom.getInstance("SHA1PRNG", "SUN");
//random = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException ex) {
ex.printStackTrace();
}
//keyGen.initialize(1024, random);
keyGen.initialize(1024);
KeyPair key = keyGen.generateKeyPair();
privKey = key.getPrivate();
pubKey = key.getPublic();
}
public String getPubKeyasString() {
//return Base64.encodeBase64String(pubKey.getEncoded());
try {
return new String(pubKey.getEncoded(),"ISO-8859-1");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public String getPriKeyasString() {
//return Base64.encodeBase64String(privKey.getEncoded());
try {
return new String(privKey.getEncoded(),"ISO-8859-1");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
答案 0 :(得分:2)
对于密钥生成,您可以使用gwt-crypto库,但要准备好应对某些性能问题和不支持的功能。
[编辑] 前段时间,我使用jsni成功地包装了一个纯粹的js rsa解决方案。我采用的是jsbn.js库
答案 1 :(得分:0)
在.gwt.xml
文件<inherits ...>
中引用另一个.gwt.xml
文件。我怀疑你使用它像java import ...
一样?
如果要在GWT中使用java.security.KeyPair
客户端,则应该做什么,以确定GWT编译器可以使用该源。这是使用<source path="..." />
文件中的.gwt.xml
条目完成的。
您可能需要访问GWT JRE Emulation Reference页面,遗憾的是您会发现没有javax.*
个软件包支持,所以祝您的项目好运......也许您应该使用代码保存仅在服务器端KeyPair
?
希望有所帮助。