diff options
author | Kenny Root <kenny@the-b.org> | 2013-02-03 19:00:31 -0800 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2013-02-03 22:59:52 -0800 |
commit | 4271e2ed172a016e9455f0e43b628a744907ce63 (patch) | |
tree | 0ee025c12c415a91d53d11d3812bbff01c7a4c43 /lib/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java | |
parent | 084ced208717d116b07bac3a3f6116f38e453a30 (diff) | |
download | sshlib-4271e2ed172a016e9455f0e43b628a744907ce63.tar.gz sshlib-4271e2ed172a016e9455f0e43b628a744907ce63.tar.bz2 sshlib-4271e2ed172a016e9455f0e43b628a744907ce63.zip |
Remove J2ME compatibility layer for keys
Use JCE instead of the DIY crypto library that is in Trilead. This was
apparently for J2ME devices. Well, I'm sorry, J2ME devices, you're dead
to me.
Diffstat (limited to 'lib/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java')
-rw-r--r-- | lib/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java b/lib/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java index df84952..30ffe0d 100644 --- a/lib/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java +++ b/lib/src/main/java/com/trilead/ssh2/crypto/digest/HashForSSH2Types.java @@ -2,6 +2,9 @@ package com.trilead.ssh2.crypto.digest;
import java.math.BigInteger;
+import java.security.DigestException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
/**
* HashForSSH2Types.
@@ -11,25 +14,24 @@ import java.math.BigInteger; */
public class HashForSSH2Types
{
- Digest md;
+ MessageDigest md;
- public HashForSSH2Types(Digest md)
+ public HashForSSH2Types(MessageDigest md)
{
this.md = md;
}
public HashForSSH2Types(String type)
{
- if (type.equals("SHA1"))
- {
- md = new SHA1();
+ try {
+ if ("SHA1".equals(type) || "MD5".equals(type)) {
+ md = MessageDigest.getInstance(type);
+ } else {
+ throw new IllegalArgumentException("Unknown algorithm " + type);
+ }
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException("Unsupported algorithm " + type);
}
- else if (type.equals("MD5"))
- {
- md = new MD5();
- }
- else
- throw new IllegalArgumentException("Unknown algorithm " + type);
}
public void updateByte(byte b)
@@ -88,6 +90,11 @@ public class HashForSSH2Types public void getDigest(byte[] out, int off)
{
- md.digest(out, off);
+ try {
+ md.digest(out, off, out.length - off);
+ } catch (DigestException e) {
+ // TODO is this right?! + throw new RuntimeException("Unable to digest", e);
+ }
}
}
|