本文整理汇总了Java中com.trilead.ssh2.signature.RSAPublicKey类的典型用法代码示例。如果您正苦于以下问题:Java RSAPublicKey类的具体用法?Java RSAPublicKey怎么用?Java RSAPublicKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RSAPublicKey类属于com.trilead.ssh2.signature包,在下文中一共展示了RSAPublicKey类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifySignature
import com.trilead.ssh2.signature.RSAPublicKey; //导入依赖的package包/类
private boolean verifySignature(byte[] sig, byte[] hostkey)
throws IOException {
if (kxs.np.server_host_key_algo.equals("ssh-rsa")) {
RSASignature rs = RSASHA1Verify.decodeSSHRSASignature(sig);
RSAPublicKey rpk = RSASHA1Verify.decodeSSHRSAPublicKey(hostkey);
log.log(50, "Verifying ssh-rsa signature");
return RSASHA1Verify.verifySignature(kxs.H, rs, rpk);
}
if (kxs.np.server_host_key_algo.equals("ssh-dss")) {
DSASignature ds = DSASHA1Verify.decodeSSHDSASignature(sig);
DSAPublicKey dpk = DSASHA1Verify.decodeSSHDSAPublicKey(hostkey);
log.log(50, "Verifying ssh-dss signature");
return DSASHA1Verify.verifySignature(kxs.H, ds, dpk);
}
throw new IOException("Unknown server host key algorithm '"
+ kxs.np.server_host_key_algo + "'");
}
示例2: addHostkey
import com.trilead.ssh2.signature.RSAPublicKey; //导入依赖的package包/类
/**
* Adds a single public key entry to the database. Note: this will NOT add
* the public key to any physical file (e.g., "~/.ssh/known_hosts") - use
* <code>addHostkeyToFile()</code> for that purpose. This method is designed
* to be used in a {@link ServerHostKeyVerifier}.
*
* @param hostnames
* a list of hostname patterns - at least one most be specified.
* Check out the OpenSSH sshd man page for a description of the
* pattern matching algorithm.
* @param serverHostKeyAlgorithm
* as passed to the {@link ServerHostKeyVerifier}.
* @param serverHostKey
* as passed to the {@link ServerHostKeyVerifier}.
* @throws IOException
*/
public void addHostkey(String hostnames[], String serverHostKeyAlgorithm,
byte[] serverHostKey) throws IOException {
if (hostnames == null)
throw new IllegalArgumentException("hostnames may not be null");
if ("ssh-rsa".equals(serverHostKeyAlgorithm)) {
RSAPublicKey rpk = RSASHA1Verify
.decodeSSHRSAPublicKey(serverHostKey);
synchronized (publicKeys) {
publicKeys.add(new KnownHostsEntry(hostnames, rpk));
}
} else if ("ssh-dss".equals(serverHostKeyAlgorithm)) {
DSAPublicKey dpk = DSASHA1Verify
.decodeSSHDSAPublicKey(serverHostKey);
synchronized (publicKeys) {
publicKeys.add(new KnownHostsEntry(hostnames, dpk));
}
} else
throw new IOException("Unknwon host key type ("
+ serverHostKeyAlgorithm + ")");
}
示例3: verifySignature
import com.trilead.ssh2.signature.RSAPublicKey; //导入依赖的package包/类
private boolean verifySignature(byte[] sig, byte[] hostkey) throws IOException
{
if (kxs.np.server_host_key_algo.equals("ssh-rsa"))
{
RSASignature rs = RSASHA1Verify.decodeSSHRSASignature(sig);
RSAPublicKey rpk = RSASHA1Verify.decodeSSHRSAPublicKey(hostkey);
log.log(50, "Verifying ssh-rsa signature");
return RSASHA1Verify.verifySignature(kxs.H, rs, rpk);
}
if (kxs.np.server_host_key_algo.equals("ssh-dss"))
{
DSASignature ds = DSASHA1Verify.decodeSSHDSASignature(sig);
DSAPublicKey dpk = DSASHA1Verify.decodeSSHDSAPublicKey(hostkey);
log.log(50, "Verifying ssh-dss signature");
return DSASHA1Verify.verifySignature(kxs.H, ds, dpk);
}
throw new IOException("Unknown server host key algorithm '" + kxs.np.server_host_key_algo + "'");
}
示例4: addHostkey
import com.trilead.ssh2.signature.RSAPublicKey; //导入依赖的package包/类
/**
* Adds a single public key entry to the database. Note: this will NOT add the public key
* to any physical file (e.g., "~/.ssh/known_hosts") - use <code>addHostkeyToFile()</code> for that purpose.
* This method is designed to be used in a {@link ServerHostKeyVerifier}.
*
* @param hostnames a list of hostname patterns - at least one most be specified. Check out the
* OpenSSH sshd man page for a description of the pattern matching algorithm.
* @param serverHostKeyAlgorithm as passed to the {@link ServerHostKeyVerifier}.
* @param serverHostKey as passed to the {@link ServerHostKeyVerifier}.
* @throws IOException
*/
public void addHostkey(String hostnames[], String serverHostKeyAlgorithm, byte[] serverHostKey) throws IOException
{
if (hostnames == null)
throw new IllegalArgumentException("hostnames may not be null");
if ("ssh-rsa".equals(serverHostKeyAlgorithm))
{
RSAPublicKey rpk = RSASHA1Verify.decodeSSHRSAPublicKey(serverHostKey);
synchronized (publicKeys)
{
publicKeys.add(new KnownHostsEntry(hostnames, rpk));
}
}
else if ("ssh-dss".equals(serverHostKeyAlgorithm))
{
DSAPublicKey dpk = DSASHA1Verify.decodeSSHDSAPublicKey(serverHostKey);
synchronized (publicKeys)
{
publicKeys.add(new KnownHostsEntry(hostnames, dpk));
}
}
else
throw new IOException("Unknwon host key type (" + serverHostKeyAlgorithm + ")");
}
示例5: matchKeys
import com.trilead.ssh2.signature.RSAPublicKey; //导入依赖的package包/类
private final boolean matchKeys(Object key1, Object key2)
{
if ((key1 instanceof RSAPublicKey) && (key2 instanceof RSAPublicKey))
{
RSAPublicKey savedRSAKey = (RSAPublicKey) key1;
RSAPublicKey remoteRSAKey = (RSAPublicKey) key2;
if (savedRSAKey.getE().equals(remoteRSAKey.getE()) == false)
return false;
if (savedRSAKey.getN().equals(remoteRSAKey.getN()) == false)
return false;
return true;
}
if ((key1 instanceof DSAPublicKey) && (key2 instanceof DSAPublicKey))
{
DSAPublicKey savedDSAKey = (DSAPublicKey) key1;
DSAPublicKey remoteDSAKey = (DSAPublicKey) key2;
if (savedDSAKey.getG().equals(remoteDSAKey.getG()) == false)
return false;
if (savedDSAKey.getP().equals(remoteDSAKey.getP()) == false)
return false;
if (savedDSAKey.getQ().equals(remoteDSAKey.getQ()) == false)
return false;
if (savedDSAKey.getY().equals(remoteDSAKey.getY()) == false)
return false;
return true;
}
return false;
}
示例6: matchKeys
import com.trilead.ssh2.signature.RSAPublicKey; //导入依赖的package包/类
private final boolean matchKeys(Object key1, Object key2) {
if ((key1 instanceof RSAPublicKey) && (key2 instanceof RSAPublicKey)) {
RSAPublicKey savedRSAKey = (RSAPublicKey) key1;
RSAPublicKey remoteRSAKey = (RSAPublicKey) key2;
if (savedRSAKey.getE().equals(remoteRSAKey.getE()) == false)
return false;
if (savedRSAKey.getN().equals(remoteRSAKey.getN()) == false)
return false;
return true;
}
if ((key1 instanceof DSAPublicKey) && (key2 instanceof DSAPublicKey)) {
DSAPublicKey savedDSAKey = (DSAPublicKey) key1;
DSAPublicKey remoteDSAKey = (DSAPublicKey) key2;
if (savedDSAKey.getG().equals(remoteDSAKey.getG()) == false)
return false;
if (savedDSAKey.getP().equals(remoteDSAKey.getP()) == false)
return false;
if (savedDSAKey.getQ().equals(remoteDSAKey.getQ()) == false)
return false;
if (savedDSAKey.getY().equals(remoteDSAKey.getY()) == false)
return false;
return true;
}
return false;
}
示例7: recommendHostkeyAlgorithms
import com.trilead.ssh2.signature.RSAPublicKey; //导入依赖的package包/类
private String[] recommendHostkeyAlgorithms(String hostname)
{
String preferredAlgo = null;
Vector keys = getAllKeys(hostname);
for (int i = 0; i < keys.size(); i++)
{
String thisAlgo = null;
if (keys.elementAt(i) instanceof RSAPublicKey)
thisAlgo = "ssh-rsa";
else if (keys.elementAt(i) instanceof DSAPublicKey)
thisAlgo = "ssh-dss";
else
continue;
if (preferredAlgo != null)
{
/* If we find different key types, then return null */
if (preferredAlgo.compareTo(thisAlgo) != 0)
return null;
/* OK, we found the same algo again, optimize */
continue;
}
}
/* If we did not find anything that we know of, return null */
if (preferredAlgo == null)
return null;
/* Now put the preferred algo to the start of the array.
* You may ask yourself why we do it that way - basically, we could just
* return only the preferred algorithm: since we have a saved key of that
* type (sent earlier from the remote host), then that should work out.
* However, imagine that the server is (for whatever reasons) not offering
* that type of hostkey anymore (e.g., "ssh-rsa" was disabled and
* now "ssh-dss" is being used). If we then do not let the server send us
* a fresh key of the new type, then we shoot ourself into the foot:
* the connection cannot be established and hence the user cannot decide
* if he/she wants to accept the new key.
*/
if (preferredAlgo.equals("ssh-rsa"))
return new String[] { "ssh-rsa", "ssh-dss" };
return new String[] { "ssh-dss", "ssh-rsa" };
}
示例8: recommendHostkeyAlgorithms
import com.trilead.ssh2.signature.RSAPublicKey; //导入依赖的package包/类
private String[] recommendHostkeyAlgorithms(String hostname) {
String preferredAlgo = null;
Vector keys = getAllKeys(hostname);
for (int i = 0; i < keys.size(); i++) {
String thisAlgo = null;
if (keys.elementAt(i) instanceof RSAPublicKey)
thisAlgo = "ssh-rsa";
else if (keys.elementAt(i) instanceof DSAPublicKey)
thisAlgo = "ssh-dss";
else
continue;
if (preferredAlgo != null) {
/* If we find different key types, then return null */
if (preferredAlgo.compareTo(thisAlgo) != 0)
return null;
/* OK, we found the same algo again, optimize */
continue;
}
}
/* If we did not find anything that we know of, return null */
if (preferredAlgo == null)
return null;
/*
* Now put the preferred algo to the start of the array. You may ask
* yourself why we do it that way - basically, we could just return only
* the preferred algorithm: since we have a saved key of that type (sent
* earlier from the remote host), then that should work out. However,
* imagine that the server is (for whatever reasons) not offering that
* type of hostkey anymore (e.g., "ssh-rsa" was disabled and now
* "ssh-dss" is being used). If we then do not let the server send us a
* fresh key of the new type, then we shoot ourself into the foot: the
* connection cannot be established and hence the user cannot decide if
* he/she wants to accept the new key.
*/
if (preferredAlgo.equals("ssh-rsa"))
return new String[] { "ssh-rsa", "ssh-dss" };
return new String[] { "ssh-dss", "ssh-rsa" };
}