📄 signdata.java
字号:
import java.io.*;
import java.security.*;
import java.security.spec.*;
public class SignData{
public static void main(String [] args)
{
FileOutputStream fileOut;
byte b;
if(args.length!=3)
{
System.out.println("Usage:SignData <PrivateKey> <dataFile> <SignatureFile>");
System.out.println("Option:");
System.out.println("<PrivateKey>:The file name of the private Key.");
System.out.println("<DataFile>: The filename that want to signature.");
System.out.println("<signatureFile>:the filename containing signture data.");
}
try{
System.out.println("Generating a digital signature....");
FileInputStream fileIn=new FileInputStream(args[0]);
byte[] encodedprivateKey=new byte[fileIn.available()];
fileIn.read(encodedprivateKey);
fileIn.close();
PKCS8EncodedKeySpec privKeySpec= new PKCS8EncodedKeySpec(encodedprivateKey);
KeyFactory keyFactory=KeyFactory.getInstance("DSA");
PrivateKey privKey=keyFactory.generatePrivate(privKeySpec);
Signature dsa=Signature.getInstance("SHA/DSA");
dsa.initSign(privKey);
FileInputStream fis=new FileInputStream(args[1]);
while(fis.available()!=0)
{
b=(byte)fis.read();
dsa.update(b);
}
fis.close();
byte[] sig=dsa.sign();
fileOut=new FileOutputStream(args[2]);
fileOut.write(sig);
fileOut.close();
System.out.println("OK");
}
catch(Exception e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -