FileDocCategorySizeDatePackage
Sha1Test.javaAPI DocAndroid 1.5 API2156Wed May 06 22:42:02 BST 2009android.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);
        }