How to implement code signing in Jini,rmi and applets

Source: Internet
Author: User
Tags command line

First paragraph code: generate a public/private key pair and specify the file on the command line to write the key pair to the file.

Import java.security.*
Import java.io.*
public class Keypairgen
{
public static void main (Stri Ng[] args
{
if (args.length!=1)
{
System.out.println (Usage:java keypairgen keyfile);
System.exit (1);
}
Keypairgen obj=new Keypairgen ();
try{
Obj.gen (args[0]);
} catch (NoSuchAlgorithmException ex)
{
System.out.println ("nosuchalgorithmexception");
}
catch (FileNotFoundException ex)
{
System.out.println ("FileNotFoundException");
}
catch (IOException ex)
{
System.out.println ("IOException");
}
}
public void Gen (String source) throws NoSuchAlgorithmException,
Filenotfoundexception,ioexception
{ br> keypairgenerator kpgen=keypairgenerator.getinstance ("DSA");
Kpgen.initialize (512);
KeyPair Kpair=kpgen.genkeypair ();
FileOutputStream fos=new FileOutputStream (source);
ObjectOutputStream oos=new objectoutputstream (FOS);
Oos.writeobject (Kpair);
Fos.close ();br> Oos.close ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.