Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 280ac138a -> 2e15fa9c4
[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/2e15fa9c Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/2e15fa9c Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/2e15fa9c Branch: refs/heads/3.0.x-fixes Commit: 2e15fa9c40f80124b302ca03ddc1ca130cb6baa5 Parents: 280ac13 Author: Sergey Beryozkin <[email protected]> Authored: Tue Mar 10 16:40:30 2015 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Tue Mar 10 16:41:19 2015 +0000 ---------------------------------------------------------------------- .../common/util/MessageDigestInputStream.java | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/2e15fa9c/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()); + } +}
