implemented symmetric key encryption.
parent
8cb72dc9de
commit
e5d64d8f2e
|
@ -36,9 +36,12 @@ import com.nimbusds.jose.JOSEException;
|
||||||
import com.nimbusds.jose.JWEAlgorithm;
|
import com.nimbusds.jose.JWEAlgorithm;
|
||||||
import com.nimbusds.jose.JWEDecrypter;
|
import com.nimbusds.jose.JWEDecrypter;
|
||||||
import com.nimbusds.jose.JWEEncrypter;
|
import com.nimbusds.jose.JWEEncrypter;
|
||||||
|
import com.nimbusds.jose.crypto.DirectDecrypter;
|
||||||
|
import com.nimbusds.jose.crypto.DirectEncrypter;
|
||||||
import com.nimbusds.jose.crypto.RSADecrypter;
|
import com.nimbusds.jose.crypto.RSADecrypter;
|
||||||
import com.nimbusds.jose.crypto.RSAEncrypter;
|
import com.nimbusds.jose.crypto.RSAEncrypter;
|
||||||
import com.nimbusds.jose.jwk.JWK;
|
import com.nimbusds.jose.jwk.JWK;
|
||||||
|
import com.nimbusds.jose.jwk.OctetSequenceKey;
|
||||||
import com.nimbusds.jose.jwk.RSAKey;
|
import com.nimbusds.jose.jwk.RSAKey;
|
||||||
import com.nimbusds.jwt.EncryptedJWT;
|
import com.nimbusds.jwt.EncryptedJWT;
|
||||||
|
|
||||||
|
@ -204,6 +207,15 @@ public class DefaultJwtEncryptionAndDecryptionService implements JwtEncryptionAn
|
||||||
|
|
||||||
// TODO: add support for EC keys
|
// TODO: add support for EC keys
|
||||||
|
|
||||||
|
} else if (jwk instanceof OctetSequenceKey) {
|
||||||
|
// build symmetric encrypters and decrypters
|
||||||
|
|
||||||
|
DirectEncrypter encrypter = new DirectEncrypter(((OctetSequenceKey) jwk).toByteArray());
|
||||||
|
DirectDecrypter decrypter = new DirectDecrypter(((OctetSequenceKey) jwk).toByteArray());
|
||||||
|
|
||||||
|
encrypters.put(id, encrypter);
|
||||||
|
decrypters.put(id, decrypter);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Unknown key type: " + jwk);
|
logger.warn("Unknown key type: " + jwk);
|
||||||
}
|
}
|
||||||
|
@ -231,12 +243,12 @@ public class DefaultJwtEncryptionAndDecryptionService implements JwtEncryptionAn
|
||||||
public Collection<JWEAlgorithm> getAllEncryptionAlgsSupported() {
|
public Collection<JWEAlgorithm> getAllEncryptionAlgsSupported() {
|
||||||
Set<JWEAlgorithm> algs = new HashSet<JWEAlgorithm>();
|
Set<JWEAlgorithm> algs = new HashSet<JWEAlgorithm>();
|
||||||
|
|
||||||
for (JWEEncrypter enc : encrypters.values()) {
|
for (JWEEncrypter encrypter : encrypters.values()) {
|
||||||
algs.addAll(enc.supportedAlgorithms());
|
algs.addAll(encrypter.supportedAlgorithms());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JWEDecrypter dec : decrypters.values()) {
|
for (JWEDecrypter decrypter : decrypters.values()) {
|
||||||
algs.addAll(dec.supportedAlgorithms());
|
algs.addAll(decrypter.supportedAlgorithms());
|
||||||
}
|
}
|
||||||
|
|
||||||
return algs;
|
return algs;
|
||||||
|
|
|
@ -16,16 +16,43 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.mitre.jwt.encryption.service.impl;
|
package org.mitre.jwt.encryption.service.impl;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.nimbusds.jose.JOSEException;
|
||||||
|
import com.nimbusds.jose.JWEAlgorithm;
|
||||||
|
import com.nimbusds.jose.jwk.JWK;
|
||||||
|
import com.nimbusds.jose.jwk.OctetSequenceKey;
|
||||||
|
import com.nimbusds.jose.jwk.Use;
|
||||||
|
import com.nimbusds.jose.util.Base64URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wkim
|
* @author wkim
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TestDefaultJwtEncryptionAndDecryptionService {
|
public class TestDefaultJwtEncryptionAndDecryptionService {
|
||||||
|
|
||||||
|
private String kid = "abc123";
|
||||||
|
|
||||||
|
private JWK jwk = new OctetSequenceKey(new Base64URL("GawgguFyGrWKav7AX4VKUg"), Use.ENCRYPTION, JWEAlgorithm.A128KW, kid);
|
||||||
|
|
||||||
|
private Map<String, JWK> keys = new ImmutableMap.Builder<String, JWK>().put(kid, jwk).build();
|
||||||
|
|
||||||
|
private DefaultJwtEncryptionAndDecryptionService service;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepare() throws NoSuchAlgorithmException, InvalidKeySpecException, JOSEException {
|
||||||
|
|
||||||
|
service = new DefaultJwtEncryptionAndDecryptionService(keys);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
fail("Not yet implemented");
|
fail("Not yet implemented");
|
||||||
|
|
Loading…
Reference in New Issue