Java Code Examples for java.security.MessageDigest.clone()

The following are Jave code examples for showing how to use clone() of the java.security.MessageDigest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: cos-java-sdk-v5   File: MD5DigestCalculatingInputStream.java   View Source Code Vote up 5 votes
private MessageDigest cloneFrom(MessageDigest from) {
    try {
        return (MessageDigest)from.clone();
    } catch (CloneNotSupportedException e) { // should never occur
        throw new IllegalStateException("unexpected", e);
    }
}
 
Example 2
Project: guava-mock   File: MessageDigestHashFunction.java   View Source Code Vote up 5 votes
private static boolean supportsClone(MessageDigest digest) {
  try {
    digest.clone();
    return true;
  } catch (CloneNotSupportedException e) {
    return false;
  }
}
 
Example 3
Project: datarouter   File: HashMethods.java   View Source Code Vote up 5 votes
private static MessageDigest initCloneableMd5(){
	try{
		MessageDigest messageDigest = createMd5Instance();
		messageDigest.clone();
		return messageDigest;
	}catch(CloneNotSupportedException ignore){
		return null;
	}
}
 
Example 4
Project: ibm-cos-sdk-java   File: MD5DigestCalculatingInputStream.java   View Source Code Vote up 5 votes
private MessageDigest cloneFrom(MessageDigest from) {
    try {
        return (MessageDigest)from.clone();
    } catch (CloneNotSupportedException e) { // should never occur
        throw new IllegalStateException("unexpected", e);
    }
}
 
Example 5
Project: googles-monorepo-demo   File: MessageDigestHashFunction.java   View Source Code Vote up 5 votes
private static boolean supportsClone(MessageDigest digest) {
  try {
    digest.clone();
    return true;
  } catch (CloneNotSupportedException e) {
    return false;
  }
}
 
Example 6
Project: openjdk-jdk10   File: TestCloning.java   View Source Code Vote up 4 votes
private static MessageDigest testCloning(MessageDigest mdObj, Provider p)
    throws Exception {

    // copy#0: clone at state BLANK w/o any data
    MessageDigest mdCopy0 = (MessageDigest) mdObj.clone();

    // copy#1: clone again at state BUFFERED w/ very short data
    mdObj.update(data1);
    mdCopy0.update(data1);
    MessageDigest mdCopy1 = (MessageDigest) mdObj.clone();

    // copy#2: clone again after updating it w/ long data to trigger
    // the state into INIT
    mdObj.update(data2);
    mdCopy0.update(data2);
    mdCopy1.update(data2);
    MessageDigest mdCopy2 = (MessageDigest) mdObj.clone();

    // copy#3: clone again after updating it w/ very short data
    mdObj.update(data1);
    mdCopy0.update(data1);
    mdCopy1.update(data1);
    mdCopy2.update(data1);
    MessageDigest mdCopy3 = (MessageDigest) mdObj.clone();

    // copy#4: clone again after updating it w/ long data
    mdObj.update(data2);
    mdCopy0.update(data2);
    mdCopy1.update(data2);
    mdCopy2.update(data2);
    mdCopy3.update(data2);
    MessageDigest mdCopy4 = (MessageDigest) mdObj.clone();

    // check digest equalities
    byte[] answer = mdObj.digest();
    byte[] result0 = mdCopy0.digest();
    byte[] result1 = mdCopy1.digest();
    byte[] result2 = mdCopy2.digest();
    byte[] result3 = mdCopy3.digest();
    byte[] result4 = mdCopy4.digest();


    check(answer, result0, "copy0");
    check(answer, result1, "copy1");
    check(answer, result2, "copy2");
    check(answer, result3, "copy3");
    check(answer, result4, "copy4");

    return mdCopy3;
}