1 /*
2 * The contents of this file are subject to the terms of the Common Development and
3 * Distribution License (the License). You may not use this file except in compliance with the
4 * License.
5 *
6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7 * specific language governing permission and limitations under the License.
8 *
9 * When distributing Covered Software, include this CDDL Header Notice in each file and include
10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11 * Header, with the fields enclosed by brackets [] replaced by your own identifying
12 * information: "Portions copyright [year] [name of copyright owner]".
13 *
14 * Copyright 2013-2015 ForgeRock AS.
15 */
16
17 package org.forgerock.json.jose.jws.handlers;
18
19 import org.forgerock.json.jose.jws.JwsAlgorithm;
20
21 /**
22 * The interface for SigningHandlers for all the different signing algorithms.
23 * <p>
24 * Provides methods for signing data and verifying the signatures of data.
25 *
26 * @since 2.0.0
27 */
28 public interface SigningHandler {
29
30 /**
31 * Signs the given String data using the Java Cryptographic algorithm defined by the JwsAlgorithm.
32 * The signature is created using the given private key.
33 *
34 * @param algorithm The JwsAlgorithm defining the Java Cryptographic algorithm.
35 * @param data The data to be signed.
36 * @return A byte array of the signature.
37 */
38 byte[] sign(JwsAlgorithm algorithm, String data);
39
40 /**
41 * Signs the given raw data bytes using the Java Cryptographic algorithm defined by the JwsAlgorithm.
42 *
43 * @param algorithm the JWS signature algorithm to use.
44 * @param data the raw data to sign.
45 * @return the signature.
46 */
47 byte[] sign(JwsAlgorithm algorithm, byte[] data);
48
49 /**
50 * Verifies that the given signature is valid for the given data.
51 * <p>
52 * Uses the Java Cryptographic algorithm defined by the JwsAlgorithm and private key to create a new signature
53 * of the data to compare against the given signature to see if they are identical.
54 *
55 * @param algorithm The JwsAlgorithm defining the JavaCryptographic algorithm.
56 * @param data The data that was signed.
57 * @param signature The signature of the data.
58 * @return <code>true</code> if the signature is a valid signature of the data.
59 */
60 boolean verify(JwsAlgorithm algorithm, byte[] data, byte[] signature);
61 }