/**
* 从私钥数据文件载入私钥
* @param file String
* @return PrivateKey
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
public static PrivateKey loadPrivateKey(String file)throws IOException,NoSuchAlgorithmException,
InvalidKeySpecException{
File f = new File(file);
if( ! f.exists())
throw new IOException("private key file not found.");
FileInputStream in = new FileInputStream(f);
byte[] privateKeyBytes = new byte[file.length()];
in.read(privateKeyBytes,0,privateKeyBytes.length);
in.close();
for(int i=0;i<privateKeyBytes.length;i++)
System.out.print(Integer.toHexString(privateKeyBytes[i]&0xFF) + " ");
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(privateKeyBytes);
KeyFactory keyf = KeyFactory.getInstance("DSA");
PrivateKey pKey = keyf.generatePrivate(priPKCS8);
return pKey;
}我用的是jdk1.4自带的包
* 从私钥数据文件载入私钥
* @param file String
* @return PrivateKey
* @throws IOException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
public static PrivateKey loadPrivateKey(String file)throws IOException,NoSuchAlgorithmException,
InvalidKeySpecException{
File f = new File(file);
if( ! f.exists())
throw new IOException("private key file not found.");
FileInputStream in = new FileInputStream(f);
byte[] privateKeyBytes = new byte[file.length()];
in.read(privateKeyBytes,0,privateKeyBytes.length);
in.close();
for(int i=0;i<privateKeyBytes.length;i++)
System.out.print(Integer.toHexString(privateKeyBytes[i]&0xFF) + " ");
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(privateKeyBytes);
KeyFactory keyf = KeyFactory.getInstance("DSA");
PrivateKey pKey = keyf.generatePrivate(priPKCS8);
return pKey;
}我用的是jdk1.4自带的包
解决方案 »
- 怎么判断两个图片是不是完全一样?
- 请哪位大侠帮忙看看,写拉一天代码,然后测试一个很简单的java类,出现下面的异常,急呀
- 什么是企业JavaBean呀?哪个大哥帮我解释一下!!!!!!!!!!!!
- jsp 里面 播放 mpg 问题,第一次打开的时候 速度非常的慢,第2次就不会,怎么回事情
- 使用SWT设计的界面,怎样实现他每次打开的时候居于显示器的中间
- 求救阿?
- 进度条中的进度是真实的程序执行进度吗?
- HELP:java设计一个文件加密解密的程序
- 下面的程序Compilation error ,如何改!
- 为什么我的jbuilder4的光标会和实际位置有两个字符的差距?我鼠标一点然后删除却是删的后两个字符。
- Application改写成Applet后 对话框怎么就弹不出来了???
- 请问,如何用JAVA得到当前系统屏幕的分辨率?
看看 jdk1.4对 key 有些什么要求!