001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2013-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.json.jose.jws.handlers; 018 019import org.forgerock.json.jose.jws.JwsAlgorithm; 020 021/** 022 * The interface for SigningHandlers for all the different signing algorithms. 023 * <p> 024 * Provides methods for signing data and verifying the signatures of data. 025 * 026 * @since 2.0.0 027 */ 028public interface SigningHandler { 029 030 /** 031 * Signs the given String data using the Java Cryptographic algorithm defined by the JwsAlgorithm. 032 * The signature is created using the given private key. 033 * 034 * @param algorithm The JwsAlgorithm defining the Java Cryptographic algorithm. 035 * @param data The data to be signed. 036 * @return A byte array of the signature. 037 */ 038 byte[] sign(JwsAlgorithm algorithm, String data); 039 040 /** 041 * Signs the given raw data bytes using the Java Cryptographic algorithm defined by the JwsAlgorithm. 042 * 043 * @param algorithm the JWS signature algorithm to use. 044 * @param data the raw data to sign. 045 * @return the signature. 046 */ 047 byte[] sign(JwsAlgorithm algorithm, byte[] data); 048 049 /** 050 * Verifies that the given signature is valid for the given data. 051 * <p> 052 * Uses the Java Cryptographic algorithm defined by the JwsAlgorithm and private key to create a new signature 053 * of the data to compare against the given signature to see if they are identical. 054 * 055 * @param algorithm The JwsAlgorithm defining the JavaCryptographic algorithm. 056 * @param data The data that was signed. 057 * @param signature The signature of the data. 058 * @return <code>true</code> if the signature is a valid signature of the data. 059 */ 060 boolean verify(JwsAlgorithm algorithm, byte[] data, byte[] signature); 061}