怎么写一个自己的安全管理器,它判断用户的密码是否正确,如果正确就可以读写文件。大侠们帮忙 怎么写一个自己的安全管理器,它判断用户的密码是否正确,如果正确就可以读写文件。大侠们帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【lovemeone】截止到2008-07-23 00:17:34的历史汇总数据(不包括此帖):发帖的总数量:2 发帖的总分数:150 每贴平均分数:75 回帖的总数量:1 得分贴总数量:0 回帖的得分率:0% 结贴的总数量:2 结贴的总分数:150 无满意结贴数:0 无满意结贴分:0 未结的帖子数:0 未结的总分数:0 结贴的百分比:100.00% 结分的百分比:100.00% 无满意结贴率:0.00 % 无满意结分率:0.00 % 敬礼! import java.io.*;public class MySecurityManager extends SecurityManager{ String password; MySecurityManager(String password) { super(); this.password = password; } private boolean VerifyPassword() { BufferedReader in= new BufferedReader (new InputStreamReader(System.in)); String inputString; System.out.println("Input Password?"); try { inputString = in.readLine(); if (inputString.equals(password)) return true; else return false; }catch (IOException e) { return false; } } public void checkRead(String filename) { if (!VerifyPassword()) throw new SecurityException("Dont read!"); else System.out.println("checkRead(String filename)"); } public void checkWrite(String filename) { if (!VerifyPassword()) throw new SecurityException("Dont write!"); else System.out.println("checkWrite(String filename)"); }}17.怎么实现数字签名啊??import java.io.*;import java.security.*;public class SignFile{ public static void main(String[] args)throws Exception { if (args.length != 1) { System.out.println("Usage: SignFile nameOfFileToSign"); System.exit(-1); } /* Generate a key keyPair */ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN"); keyGen.initialize(1024, random); KeyPair keyPair = keyGen.generateKeyPair(); PrivateKey priKey = keyPair.getPrivate(); PublicKey pubKey = keyPair.getPublic(); //print keyGen and key info System.out.println("keygen algo= "+keyGen.getAlgorithm()); System.out.println("keygen provider= "+keyGen.getProvider()); System.out.println("key algo= "+pubKey.getAlgorithm()); System.out.println("key format= "+pubKey.getFormat()); // Create a Signature object and initialize it Signature signObject = Signature.getInstance("SHA1withDSA", "SUN"); signObject.initSign(priKey); /* supply data to to sign the data */ DataInputStream in=new DataInputStream (new FileInputStream(args[0])); byte[] data = new byte[1024]; in.read(data); signObject.update(data); in.close(); /* sign data(create signature) */ byte[] signature = signObject.sign(); /* Save the signature in a file */ FileOutputStream signatureFile = new FileOutputStream("signature.txt"); signatureFile.write(signature); signatureFile.close(); /* Save the public key in a file */ byte[] key = pubKey.getEncoded(); FileOutputStream pubKeyFile = new FileOutputStream("publicKey.txt"); pubKeyFile.write(key); pubKeyFile.close(); }} 问一个JAVA泛型问题 求急速解决 自动灌水问题求救。很简单的问题,谁答对了分全给 求助: java可否调用matlab 生成的 .m文件 怎么知道自己的可用分是多少? 谁能告诉我struct,spring,hibernate到底是什么? 刚刚开始学JAVA,一个小问题,请大家帮忙看一下! 为什么别人可以访问我,我自己却不能(apache服务) 请问:如何在页面上加入一段javascript程序,使得页面上的所有连接都在新窗口中打开? LinkedList的对象不能访问其方法,什么回事 怎么应用绘图工具啊?? 超级分享一下 oracle的rownum,都该进来看下,相信大部分能解决你的问题
楼主【lovemeone】截止到2008-07-23 00:17:34的历史汇总数据(不包括此帖):
发帖的总数量:2 发帖的总分数:150 每贴平均分数:75
回帖的总数量:1 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:2 结贴的总分数:150
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:0.00 % 无满意结分率:0.00 %
敬礼!
public class MySecurityManager extends SecurityManager
{
String password;
MySecurityManager(String password)
{
super();
this.password = password;
}
private boolean VerifyPassword()
{
BufferedReader in= new BufferedReader
(new InputStreamReader(System.in));
String inputString;
System.out.println("Input Password?");
try
{
inputString = in.readLine();
if (inputString.equals(password))
return true;
else
return false;
}catch (IOException e)
{
return false;
}
}
public void checkRead(String filename)
{
if (!VerifyPassword())
throw new SecurityException("Dont read!");
else
System.out.println("checkRead(String filename)");
}
public void checkWrite(String filename)
{
if (!VerifyPassword())
throw new SecurityException("Dont write!");
else
System.out.println("checkWrite(String filename)");
}
}17.怎么实现数字签名啊??
import java.io.*;
import java.security.*;
public class SignFile
{
public static void main(String[] args)throws Exception
{
if (args.length != 1)
{
System.out.println("Usage: SignFile nameOfFileToSign");
System.exit(-1);
}
/* Generate a key keyPair */
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(1024, random);
KeyPair keyPair = keyGen.generateKeyPair();
PrivateKey priKey = keyPair.getPrivate();
PublicKey pubKey = keyPair.getPublic();
//print keyGen and key info
System.out.println("keygen algo= "+keyGen.getAlgorithm());
System.out.println("keygen provider= "+keyGen.getProvider());
System.out.println("key algo= "+pubKey.getAlgorithm());
System.out.println("key format= "+pubKey.getFormat());
// Create a Signature object and initialize it
Signature signObject = Signature.getInstance("SHA1withDSA", "SUN");
signObject.initSign(priKey);
/* supply data to to sign the data */
DataInputStream in=new DataInputStream
(new FileInputStream(args[0]));
byte[] data = new byte[1024];
in.read(data);
signObject.update(data);
in.close();
/* sign data(create signature) */
byte[] signature = signObject.sign();
/* Save the signature in a file */
FileOutputStream signatureFile = new FileOutputStream("signature.txt");
signatureFile.write(signature);
signatureFile.close();
/* Save the public key in a file */
byte[] key = pubKey.getEncoded();
FileOutputStream pubKeyFile = new FileOutputStream("publicKey.txt");
pubKeyFile.write(key);
pubKeyFile.close();
}
}