如何在我的gwt应用程序中导入java.security。* [英] how to import java.security.* in my gwt application
问题描述
我想用gwt开发一个插件。它必须使用java.security。*作为客户端的密钥生成。
i已经提出所有要求
但它显示以下错误。
加载模块
coreservlets.GwtApp1
加载继承模块'coreservlets.GwtApp1'
加载继承模块'java.security.KeyPair'
[错误]无法在您的类路径中找到'java / security / KeyPair.gwt.xml'; >可能是拼写错误,或者您可能忘记为源代码包含类路径条目?
[错误]第15行:处理元素'继承'时出现意外异常
我在我的gwtapp1.gwt.xml文件中继承了所有相关的类,比如java.security.KeyPair。
我还将jar包含在classpath本身中但仍然错误没有消失。
我应该怎么做.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;
私钥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;
尝试{
keyGen = KeyPairGenerator.getInstance(ALGORITHAM);
} catch(NoSuchAlgorithmException ex){
ex.printStackTrace();
}
尝试{
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();
$ b public String getPubKeyasString(){
// return Base64.encodeBase64String(pubKey.getEncoded());
try {
return new String(pubKey.getEncoded(),ISO-8859-1);
} catch(UnsupportedEncodingException e){
// TODO自动生成的catch块
e.printStackTrace();
}
返回null;
}
public String getPriKeyasString(){
// return Base64.encodeBase64String(privKey.getEncoded());
尝试{
返回新字符串(privKey.getEncoded(),ISO-8859-1);
} catch(UnsupportedEncodingException e){
// TODO自动生成的catch块
e.printStackTrace();
}
返回null;
}
}
对于密钥生成,您可以使用 gwt-crypto library,但要准备好某些性能问题和不支持的功能。
前段时间,我成功地封装了一个纯粹的js rsa解决方案使用jsni。我带的js是 jsbn.js 图书馆
i want to develop a plugin using gwt. It has to use java.security.* for the key generation on client side. i have made all requirement But it is showing following error.
Loading modules
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'
i have inherited all the related class like "java.security.KeyPair" in my gwtapp1.gwt.xml file
also i included jar in classpath itself.but still the error has not gone. what should i do.plz suggest here is my java code
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;
}
}
For key generation you can use the gwt-crypto library, but be prepared to certain performance issues and unsupported features.
[Edit] Some time ago, I did success wrapping a pure js rsa solution using jsni. The js I took was the jsbn.js library
这篇关于如何在我的gwt应用程序中导入java.security。*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!