com.theicenet.cryptography.mac.MacService Maven / Gradle / Ivy
/*
* Copyright 2019-2020 the original author or authors.
*
* 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
*
* https://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 com.theicenet.cryptography.mac;
import java.io.InputStream;
import javax.crypto.SecretKey;
/**
* A MacService instance is a component which implements a secret key cryptography
* (symmetric cryptography) mechanism to work with message authentication code (MAC).
* This is used to confirm that the message came from the stated sender (its authenticity) and
* has not been changed (its integrity).
*
* @see Message authentication code
* @see Symmetric-key algorithm
*
* @apiNote Any implementation of this interface must be unconditionally thread-safe.
*
* @author Juan Fidalgo
* @since 1.0.0
*/
public interface MacService {
/**
* Calculates the message authentication code (MAC) for the passed content
* using the passed secretKey (secret key cryptography).
*
* @param secretKey secret key (symmetric cryptography) to use to calculate the
* message authentication code (MAC)
* @param content content to calculate the message authentication code (MAC)
* @return Calculated message authentication code (MAC) which has been produced for
* content using the secretKey (symmetric cryptography)
*/
byte[] calculateMac(SecretKey secretKey, byte[] content);
/**
* Calculates the message authentication code (MAC) for the passed input
* contentInputStream using the passed secretKey (secret key cryptography).
*
* @apiNote Once this method returns the input stream must have been closed so it can't be mutated.
*
* @param secretKey secret key (symmetric cryptography) to use to calculate the
* message authentication code (MAC)
* @param contentInputStream input stream with the content to calculate the
* message authentication code (MAC)
* @return Calculated message authentication code (MAC) which has been produced for
* content using the secretKey (symmetric cryptography)
*/
byte[] calculateMac(SecretKey secretKey, InputStream contentInputStream);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy