コード例 #1
0
 @Test
 public void testVerifyCode() throws Exception {
   for (String algorithm : algs) {
     for (String key : keys) {
       for (int i = 0; i < testStrings.length; ++i) {
         InputStream in = IOUtils.toInputStream(testStrings[i]);
         InputStream keyStream = IOUtils.toInputStream(key);
         InputStream code =
             new ByteArrayInputStream(
                 Hex.decodeHex(codes.get(algorithm).get(key)[i].toCharArray()));
         assert (MessageAuthenticator.verifyCode(algorithm, in, keyStream, code));
         in = IOUtils.toInputStream(testStrings[i]);
         keyStream = IOUtils.toInputStream(key);
         code =
             new ByteArrayInputStream(
                 Hex.decodeHex(
                     codes.get(algorithm).get(key)[(i + 1) % testStrings.length].toCharArray()));
         assertFalse(MessageAuthenticator.verifyCode(algorithm, in, keyStream, code));
       }
     }
   }
 }