码迷,mamicode.com
首页 > 其他好文 > 详细

KeyProvider

时间:2017-12-02 19:22:50      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:decode   mpi   erro   匹配   row   UI   val   creat   error   

private PublicKey pubKey;

public PublicKey getPublic() throws IOException {
return this.pubKey != null ? this.pubKey : super.getPublic();
}

public void init(File location) {
File f = new File(location + ".pub");
if (f.exists()) {
try {
this.initPubKey(new FileReader(f));
} catch (IOException var4) {
this.log.warn("Error reading public key file: {}", var4.toString());
}
}

super.init(location);
}

public void init(String privateKey, String publicKey) {
if (publicKey != null) {
this.initPubKey(new StringReader(publicKey));
}

super.init(privateKey, null);
}

private void initPubKey(Reader publicKey) {
this.type = KeyType.DSA;
try {
StringBuilder publicKeyString = new StringBuilder();
try (BufferedReader br = new BufferedReader(publicKey)) {
String keydata;
while ((keydata = br.readLine()) != null) {
if (skipInvalid(keydata)) {
publicKeyString.append(keydata);
}
}
this.pubKey = (new Buffer.PlainBuffer(Base64.decode(publicKeyString.toString()))).readPublicKey();
}
} catch (IOException var9) {
this.log.warn("Error reading public key: {}", var9.toString());
}

}

private boolean skipInvalid(String keydata) {

String regEx = "[-:\"]";
// 编译正则表达式
Pattern pattern = Pattern.compile(regEx);
// 忽略大小写的写法
// Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(keydata);
// 字符串是否与正则表达式相匹配
return matcher.matches();
}

// public static class Factory implements net.schmizz.sshj.common.Factory.Named<FileKeyProvider> {
// public Factory() {
// }
//
// public FileKeyProvider create() {
// return new SSH2KeyProvider();
// }
//
// public String getName() {
// return "SSH2";
// }
// }

KeyProvider

标签:decode   mpi   erro   匹配   row   UI   val   creat   error   

原文地址:http://www.cnblogs.com/breakyang/p/7955012.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!