diff options
author | Yana Stamcheva <yana@jitsi.org> | 2009-07-28 16:07:46 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2009-07-28 16:07:46 +0000 |
commit | c98f98655f7dd2a7eb21868a08032554fe0c97b9 (patch) | |
tree | b77d9fee0637f4cfc18fb83143c3f5f7538dbabf /src/net/java/sip/communicator/util/Sha1Crypto.java | |
parent | 425a1abaf81dbb9c496296ae51749a2754cd9f30 (diff) | |
download | jitsi-c98f98655f7dd2a7eb21868a08032554fe0c97b9.zip jitsi-c98f98655f7dd2a7eb21868a08032554fe0c97b9.tar.gz jitsi-c98f98655f7dd2a7eb21868a08032554fe0c97b9.tar.bz2 |
- Some improvements in "feature" introducing in Jabber.
- Support for thumbnails in Jabber file transfer.
- Fixed some issues with the calculated file transfer speed and estimated transfer time.
- Shows open and open folder links also on the sender side when the transfer is completed.
Diffstat (limited to 'src/net/java/sip/communicator/util/Sha1Crypto.java')
-rw-r--r-- | src/net/java/sip/communicator/util/Sha1Crypto.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/util/Sha1Crypto.java b/src/net/java/sip/communicator/util/Sha1Crypto.java new file mode 100644 index 0000000..692a075 --- /dev/null +++ b/src/net/java/sip/communicator/util/Sha1Crypto.java @@ -0,0 +1,76 @@ +package net.java.sip.communicator.util; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class Sha1Crypto +{ + /** + * Encodes the given text with the SHA-1 algorithm. + * + * @param text the text to encode + * @return the encoded text + * @throws NoSuchAlgorithmException + * @throws UnsupportedEncodingException + */ + public static String encode(String text) + throws NoSuchAlgorithmException, + UnsupportedEncodingException + { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); + + byte[] sha1hash; + messageDigest.update(text.getBytes("iso-8859-1"), 0, text.length()); + sha1hash = messageDigest.digest(); + + return convertToHex(sha1hash); + } + + /** + * Encodes the given text with the SHA-1 algorithm. + * + * @param byteArreay the byte array to encode + * @return the encoded text + * @throws NoSuchAlgorithmException + * @throws UnsupportedEncodingException + */ + public static String encode(byte[] byteArray) + throws NoSuchAlgorithmException, + UnsupportedEncodingException + { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); + + byte[] sha1hash; + messageDigest.update(byteArray); + sha1hash = messageDigest.digest(); + + return convertToHex(sha1hash); + } + + /** + * Converts the given byte data into Hex string. + * + * @param data the byte array to convert + * @return the Hex string representation of the given byte array + */ + private static String convertToHex(byte[] data) + { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < data.length; i++) + { + int halfbyte = (data[i] >>> 4) & 0x0F; + int two_halfs = 0; + do + { + if ((0 <= halfbyte) && (halfbyte <= 9)) + buf.append((char) ('0' + halfbyte)); + else + buf.append((char) ('a' + (halfbyte - 10))); + halfbyte = data[i] & 0x0F; + } + while(two_halfs++ < 1); + } + return buf.toString(); + } +} |