Code example for ObjectInputStream

Methods: closereadObject

0
{ 
	public static void main(String[] args) throws Exception, IOException
	{ 
		String myinfo = "this is my message";
 
		ObjectInputStream in = new ObjectInputStream( new FileInputStream( "myprikey.dat" ) );
		PrivateKey myprikey = (PrivateKey) in.readObject();
		in.close();
		// 初始一个Signature对象,并用私钥对信息签名 
		java.security.Signature signet = java.security.Signature.getInstance( "DSA" );
		signet.initSign( myprikey );
		signet.update( myinfo.getBytes() );
		byte[] signed = signet.sign();
		// 把信息和签名保存在一个文件中(myinfo.dat) 
		ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream( "myinfo.dat" ) );
		out.writeObject( myinfo );
		out.writeObject( signed );
		out.close();
		// 把他的公钥的信息及签名发给其它用户 
	} 
Stop searching for code, let great code find you!  Add Codota to your java IDE