All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fisco.bcos.sdk.crypto.hash.SM3Hash Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
/**
 * Copyright 2014-2020 [fisco-dev]
 *
 * 

Licensed 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.fisco.bcos.sdk.crypto.hash; import com.webank.wedpr.crypto.CryptoResult; import com.webank.wedpr.crypto.NativeInterface; import org.fisco.bcos.sdk.crypto.exceptions.HashException; import org.fisco.bcos.sdk.utils.Hex; public class SM3Hash implements Hash { @Override public String hash(final String inputData) { return calcualteHash(inputData.getBytes()); } @Override public byte[] hash(final byte[] inputBytes) { // Considering inefficient string conversion, this interface is not recommended return Hex.decode(calcualteHash(inputBytes)); } private String calcualteHash(final byte[] inputBytes) { CryptoResult hashResult = NativeInterface.sm3(Hex.toHexString(inputBytes)); // call sm3 failed if (hashResult.wedprErrorMessage != null && !hashResult.wedprErrorMessage.isEmpty()) { throw new HashException( "calculate hash with sm3 failed, error message:" + hashResult.wedprErrorMessage); } return hashResult.hash; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy