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; 018 019import org.forgerock.json.jose.jws.handlers.HmacSigningHandler; 020import org.forgerock.json.jose.jws.handlers.NOPSigningHandler; 021import org.forgerock.json.jose.jws.handlers.RSASigningHandler; 022import org.forgerock.json.jose.jws.handlers.SigningHandler; 023import org.forgerock.util.SignatureUtil; 024 025import java.security.Key; 026 027/** 028 * A service to get the appropriate SigningHandler for a specific Java Cryptographic signing algorithm. 029 * <p> 030 * For details of all supported signing algorithms see {@link JwsAlgorithm} 031 * 032 * @since 2.0.0 033 */ 034public class SigningManager { 035 036 private final SignatureUtil signatureUtil = SignatureUtil.getInstance(); 037 038 /** 039 * Constructs an implementation of the SigningHandler which does not perform 040 * any signing or verifying. 041 * 042 * @return an implementation of the SigningHandler which does not perform 043 * any signing or verifying. 044 */ 045 public SigningHandler newNopSigningHandler() { 046 return new NOPSigningHandler(); 047 } 048 049 /** 050 * Constructs a new HmacSigningHandler. 051 * 052 * @param sharedSecret 053 * The shared secret to use to sign the data. 054 * @return a new HmacSigningHandler. 055 */ 056 public SigningHandler newHmacSigningHandler(byte[] sharedSecret) { 057 return new HmacSigningHandler(sharedSecret); 058 } 059 060 /** 061 * Constructs a new RSASigningHandler, with a SignatureUtil instance to 062 * delegate the signing and verifying calls to. 063 * 064 * @param key 065 * The key used to sign and verify the signature. 066 * @return a new RSASigningHandler, with a SignatureUtil instance to 067 * delegate the signing and verifying calls to. 068 */ 069 public SigningHandler newRsaSigningHandler(Key key) { 070 return new RSASigningHandler(key, signatureUtil); 071 } 072}