Repository: cxf Updated Branches: refs/heads/master eadcd2ce0 -> e805911d4
[CXF-6278] Adding a utility DigestInputStream extension Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e805911d Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e805911d Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e805911d Branch: refs/heads/master Commit: e805911d436ed242d2e3e7489c1b1f6dfc36a189 Parents: eadcd2c Author: Sergey Beryozkin <[email protected]> Authored: Tue Mar 10 16:40:30 2015 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Tue Mar 10 16:40:30 2015 +0000 ---------------------------------------------------------------------- .../common/util/MessageDigestInputStream.java | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/e805911d/core/src/main/java/org/apache/cxf/common/util/MessageDigestInputStream.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/common/util/MessageDigestInputStream.java b/core/src/main/java/org/apache/cxf/common/util/MessageDigestInputStream.java new file mode 100644 index 0000000..0237b8d --- /dev/null +++ b/core/src/main/java/org/apache/cxf/common/util/MessageDigestInputStream.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.common.util; + +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.cxf.common.util.crypto.MessageDigestUtils; + +public class MessageDigestInputStream extends java.security.DigestInputStream { + public MessageDigestInputStream(InputStream is) { + super(is, getDigestInstance(MessageDigestUtils.ALGO_SHA_256)); + } + + private static MessageDigest getDigestInstance(String algo) { + try { + return MessageDigest.getInstance(algo); + } catch (NoSuchAlgorithmException ex) { + throw new SecurityException(ex); + } + } + public byte[] getDigestBytes() { + return super.getMessageDigest().digest(); + } + public String getBase64Digest() { + return Base64Utility.encode(getDigestBytes()); + } + public String getBase64UrlDigest() { + return Base64UrlUtility.encode(getDigestBytes()); + } +}
