// Run 'message' through streamEncrypt byte[] se = streamEncrypt(message, key, digest); // 'digest' already has the value from the stream, just finish the op byte[] sd = digest.digest();
digest.reset(); // Run 'message' through blockEncrypt byte[] be = blockEncrypt(message, key); // Take digest of encrypted blockEncrypt result byte[] bd = digest.digest(be); // Verify both returned the same value if (!Arrays.equals(sd, bd)) {
System.err.println("Stream: "+ printHexBinary(se)+ "\t Digest: "+ printHexBinary(sd));
System.err.println("Block : "+printHexBinary(be)+ "\t Digest: "+ printHexBinary(bd)); thrownew Exception("stream & block encryption does not match");
}
digest.reset(); // Sanity check: Decrypt separately from stream to verify operations
String bm = (String) blockDecrypt(be, key); if (message.compareTo(bm) != 0) {
System.err.println("Expected: "+message+"\nBlock: "+bm); thrownew Exception("Block decryption does not match expected");
}
// Have decryption and digest included in the object stream
String sm = (String) streamDecrypt(se, key, digest); if (message.compareTo(sm) != 0) {
System.err.println("Expected: "+message+"\nStream: "+sm); thrownew Exception("Stream decryption does not match expected.");
}
}
publicstaticbyte[] parseHexBinary(String s) { finalint len = s.length();
// "111" is not a valid hex encoding. if (len % 2 != 0) { thrownew IllegalArgumentException("hexBinary needs to be even-length: " + s);
}
byte[] out = newbyte[len / 2];
for (int i = 0; i < len; i += 2) { int h = hexToBin(s.charAt(i)); int l = hexToBin(s.charAt(i + 1)); if (h == -1 || l == -1) { thrownew IllegalArgumentException("contains illegal character for hexBinary: " + s);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.