From df4c1981bacb0300082899e19a8268df94f36aa0 Mon Sep 17 00:00:00 2001 From: Derek DeMoro Date: Tue, 18 Oct 2005 15:43:22 +0000 Subject: [PATCH] Added getAvatarHash to allow for avatar updates. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2974 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smackx/packet/VCard.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source/org/jivesoftware/smackx/packet/VCard.java b/source/org/jivesoftware/smackx/packet/VCard.java index daf51747c..1c8fc3746 100644 --- a/source/org/jivesoftware/smackx/packet/VCard.java +++ b/source/org/jivesoftware/smackx/packet/VCard.java @@ -34,6 +34,8 @@ import java.io.InputStream; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.net.URL; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -309,6 +311,7 @@ public class VCard extends IQ { /** * Specify the bytes for the avatar to use. + * * @param bytes the bytes of the avatar. */ public void setAvatar(byte[] bytes) { @@ -377,6 +380,28 @@ public class VCard extends IQ { return buffer; } + /** + * Returns the SHA-1 Hash of the Avatar image. + * @return the SHA-1 Hash of the Avatar image. + */ + public String getAvatarHash() { + byte[] bytes = getAvatar(); + if (bytes == null) { + return null; + } + + MessageDigest digest = null; + try { + digest = MessageDigest.getInstance("SHA-1"); + } + catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + + digest.update(bytes); + return StringUtils.encodeHex(digest.digest()); + } + /** * Save this vCard for the user connected by 'connection'. Connection should be authenticated * and not anonymous.