FileDocCategorySizeDatePackage
Sha1Test.javaAPI DocAndroid 5.1 API2153Thu Mar 12 22:22:42 GMT 2015android.core

Sha1Test

public class Sha1Test extends TestCase
Tests SHA1 message digest algorithm.

Fields Summary
TestData[]
mTestData
Constructors Summary
Methods Summary
private static java.lang.StringencodeHex(byte[] bytes)

        StringBuffer hex = new StringBuffer(bytes.length * 2);

        for (int i = 0; i < bytes.length; i++) {
            if (((int) bytes[i] & 0xff) < 0x10) {
                hex.append("0");
            }
            hex.append(Integer.toString((int) bytes[i] & 0xff, 16));
        }

        return hex.toString();
    
public voidtestSha1()


    
         
        MessageDigest digest = MessageDigest.getInstance("SHA-1");

        int numTests = mTestData.length;
        for (int i = 0; i < numTests; i++) {
            digest.update(mTestData[i].input.getBytes());
            byte[] hash = digest.digest();
            String encodedHash = encodeHex(hash);
            assertEquals(encodedHash, mTestData[i].result);
        }