001/******************************************************************************* 002 * Copyright 2017 The MIT Internet Trust Consortium 003 * 004 * Portions copyright 2011-2013 The MITRE Corporation 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 *******************************************************************************/ 018package org.mitre.jwt.encryption.service; 019 020import java.util.Collection; 021import java.util.Map; 022 023import com.nimbusds.jose.EncryptionMethod; 024import com.nimbusds.jose.JWEAlgorithm; 025import com.nimbusds.jose.JWEObject; 026import com.nimbusds.jose.jwk.JWK; 027 028/** 029 * @author wkim 030 * 031 */ 032public interface JWTEncryptionAndDecryptionService { 033 034 /** 035 * Encrypts the JWT in place with the default encrypter. 036 * If an arbitrary payload is used, then pass in a JWEObject. 037 * Otherwise, if JWT claims are the payload, then use the JWEObject subclass EncryptedJWT instead. 038 * @param jwt 039 */ 040 public void encryptJwt(JWEObject jwt); 041 042 /** 043 * Decrypts the JWT in place with the default decrypter. 044 * If an arbitrary payload is used, then pass in a JWEObject. 045 * Otherwise, if JWT claims are the payload, then use the JWEObject subclass EncryptedJWT instead. 046 * @param jwt 047 */ 048 public void decryptJwt(JWEObject jwt); 049 050 /** 051 * Get all public keys for this service, mapped by their Key ID 052 */ 053 public Map<String, JWK> getAllPublicKeys(); 054 055 /** 056 * Get the list of all encryption algorithms supported by this service. 057 * @return 058 */ 059 public Collection<JWEAlgorithm> getAllEncryptionAlgsSupported(); 060 061 /** 062 * Get the list of all encryption methods supported by this service. 063 * @return 064 */ 065 public Collection<EncryptionMethod> getAllEncryptionEncsSupported(); 066 067 /** 068 * TODO add functionality for encrypting and decrypting using a specified key id. 069 * Example: public void encryptJwt(EncryptedJWT jwt, String kid); 070 */ 071}