Java Code Examples for org.jivesoftware.smack.util.StringUtils#encodeHex()

The following examples show how to use org.jivesoftware.smack.util.StringUtils#encodeHex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VCard.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    try {
        digest = MessageDigest.getInstance("SHA-1");
    }
    catch (NoSuchAlgorithmException e) {
        LOGGER.log(Level.SEVERE, "Failed to get message digest", e);
        return null;
    }

    digest.update(bytes);
    return StringUtils.encodeHex(digest.digest());
}
 
Example 2
Source File: SASLDigestMD5Mechanism.java    From Smack with Apache License 2.0 6 votes vote down vote up
private String calcResponse(DigestType digestType) {
    StringBuilder a2 = new StringBuilder();
    if (digestType == DigestType.ClientResponse) {
        a2.append("AUTHENTICATE");
    }
    a2.append(':');
    a2.append(digestUri);
    String hex_hashed_a2 = StringUtils.encodeHex(MD5.bytes(a2.toString()));

    StringBuilder kd_argument = new StringBuilder();
    kd_argument.append(hex_hashed_a1);
    kd_argument.append(':');
    kd_argument.append(nonce);
    kd_argument.append(':');
    kd_argument.append(INITAL_NONCE);
    kd_argument.append(':');
    kd_argument.append(cnonce);
    kd_argument.append(':');
    kd_argument.append(QOP_VALUE);
    kd_argument.append(':');
    kd_argument.append(hex_hashed_a2);
    byte[] kd = MD5.bytes(kd_argument.toString());
    String responseValue = StringUtils.encodeHex(kd);
    return responseValue;
}
 
Example 3
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void md5Test() {
    String actual = StringUtils.encodeHex(HashManager.md5(array()));
    assertEquals(md5sum, actual);
}
 
Example 4
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha1Test() {
    String actual = StringUtils.encodeHex(HashManager.sha_1(array()));
    assertEquals(sha1sum, actual);
}
 
Example 5
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha224Test() {
    String actual = StringUtils.encodeHex(HashManager.sha_224(array()));
    assertEquals(sha224sum, actual);
}
 
Example 6
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha256Test() {
    String actual = StringUtils.encodeHex(HashManager.sha_256(array()));
    assertEquals(sha256sum, actual);
}
 
Example 7
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha384Test() {
    String actual = StringUtils.encodeHex(HashManager.sha_384(array()));
    assertEquals(sha384sum, actual);
}
 
Example 8
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha512Test() {
    String actual = StringUtils.encodeHex(HashManager.sha_512(array()));
    assertEquals(sha512sum, actual);
}
 
Example 9
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha3_224Test() {
    String actual = StringUtils.encodeHex(HashManager.sha3_224(array()));
    assertEquals(sha3_224sum, actual);
}
 
Example 10
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha3_256Test() {
    String actual = StringUtils.encodeHex(HashManager.sha3_256(array()));
    assertEquals(sha3_256sum, actual);
}
 
Example 11
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha3_384Test() {
    String actual = StringUtils.encodeHex(HashManager.sha3_384(array()));
    assertEquals(sha3_384sum, actual);
}
 
Example 12
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void sha3_512Test() {
    String actual = StringUtils.encodeHex(HashManager.sha3_512(array()));
    assertEquals(sha3_512sum, actual);
}
 
Example 13
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void blake2b160Test() {
    String actual = StringUtils.encodeHex(HashManager.blake2b160(array()));
    assertEquals(b2_160sum, actual);
}
 
Example 14
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void blake2b256Test() {
    String actual = StringUtils.encodeHex(HashManager.blake2b256(array()));
    assertEquals(b2_256sum, actual);
}
 
Example 15
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void blake2b384Test() {
    String actual = StringUtils.encodeHex(HashManager.blake2b384(array()));
    assertEquals(b2_384sum, actual);
}
 
Example 16
Source File: HashTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Test
public void blake2b512Test() {
    String actual = StringUtils.encodeHex(HashManager.blake2b512(array()));
    assertEquals(b2_512sum, actual);
}