SHA { public static byte[] encryptSHA(byte[] data) throws Exception { MessageDigest sha = MessageDigest.getInstance(KEY_SHA1); sha.update(data); return sha.digest(); } SHA(); static byte[] encryptSHA(byte[] data); static String encryptSHA(String data); static String encryptSHA(String str,String ecryptCode); static void main(String[] args);  }
@Test public void testEncryptSHA() throws Exception { final byte[] data = {112, 55, -128, 113, -104, -62, 42, 125, 43, 8, 7, 55, 29, 118, 55, 121, -88, 79, -33, -49}; Assert.assertArrayEquals(data, SHA.encryptSHA(new byte[]{1, 2, 3})); }
@Test public void testEncryptSHAString() throws Exception { Assert.assertEquals("", SHA.encryptSHA((String) null)); Assert.assertEquals(SHA_foo, SHA.encryptSHA("foo")); Assert.assertEquals(SHA_bar, SHA.encryptSHA("bar")); }
@Test public void testEncryptSHAStringString() throws NoSuchAlgorithmException { Assert.assertEquals("", SHA.encryptSHA(null, null)); Assert.assertEquals(SHA_foo, SHA.encryptSHA("foo", "SHA")); Assert.assertEquals(SHA_1_foo, SHA.encryptSHA("foo", "SHA-1")); Assert.assertEquals(SHA_256_foo, SHA.encryptSHA("foo", "SHA-256")); Assert.assertEquals(SHA_bar, SHA.encryptSHA("bar", "SHA")); Assert.assertEquals(SHA_1_bar, SHA.encryptSHA("bar", "SHA-1")); Assert.assertEquals(SHA_256_bar, SHA.encryptSHA("bar", "SHA-256")); }