Package org.jose4j.keys

Examples of org.jose4j.keys.AesKey


public class OctJwkGenerator
{
    public static OctetSequenceJsonWebKey generateJwk(int keyLengthInBits)
    {
        byte[] bytes = ByteUtil.randomBytes(ByteUtil.byteLength(keyLengthInBits));
        return new OctetSequenceJsonWebKey(new AesKey(bytes));
    }
View Full Code Here


            byte[] aad = new byte[] {97,97,100};
            byte[] cek = new byte[keyByteLength];
            byte[] iv = new byte[ivByteLength];
            try
            {
                encrypt(new AesKey(cek), iv, plain, aad);
                isAvailable = true;
            }
            catch (JoseException e)
            {
                log.debug(joseAlg + " is not available (" + ExceptionHelp.toStringWithCauses(e) + ").");
View Full Code Here

    }

    ContentEncryptionParts encrypt(byte[] plaintext, byte[] aad, byte[] key, byte[] iv) throws JoseException
    {
        Key hmacKey = new HmacKey(ByteUtil.leftHalf(key));
        Key encryptionKey = new AesKey(ByteUtil.rightHalf(key));

        Cipher cipher = CipherUtil.getCipher(getJavaAlgorithm());

        try
        {
View Full Code Here

            String encTag = base64Url.base64UrlEncode(authenticationTag);
            String calcEncTag = base64Url.base64UrlEncode(calculatedAuthenticationTag);
            throw new IntegrityException("Authentication tag check failed. Message=" + encTag + " calculated=" + calcEncTag);
        }

        Key encryptionKey = new AesKey(ByteUtil.rightHalf(contentEncryptionKey));

        Cipher cipher = CipherUtil.getCipher(getJavaAlgorithm());
        try
        {
            cipher.init(Cipher.DECRYPT_MODE, encryptionKey, new IvParameterSpec(iv));
View Full Code Here

        JsonWebKey jsonWebKey = JsonWebKey.Factory.newJwk("\n" +
                "     {\"kty\":\"oct\",\n" +
                "      \"k\":\"GawgguFyGrWKav7AX4VKUg\"\n" +
                "     }");
        AesKey managementKey = new AesKey(jsonWebKey.getKey().getEncoded());

        WrappingKeyManagementAlgorithm wrappingKeyManagementAlgorithm = new AesKeyWrapManagementAlgorithm.Aes128();

        ContentEncryptionAlgorithm contentEncryptionAlgorithm = new AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256();
        ContentEncryptionKeyDescriptor cekDesc = contentEncryptionAlgorithm.getContentEncryptionKeyDescriptor();
View Full Code Here

        JsonWebEncryption jwe = new JsonWebEncryption();
        String plaintext = "This should compress pretty good, it should, yes it should pretty good it should" +
                " pretty good it should it should it should it should pretty good it should pretty good it should" +
                " pretty good it should pretty good it should pretty good it should pretty good it should pretty good.";
        jwe.setPlaintext(plaintext);
        AesKey key = new AesKey(ByteUtil.randomBytes(32));
        jwe.setKey(key);
        jwe.setHeader(HeaderParameterNames.ZIP, CompressionAlgorithmIdentifiers.DEFLATE);
        jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
        jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
View Full Code Here

    public void testJweBadZipValueProduce() throws JoseException
    {
        JsonWebEncryption jwe = new JsonWebEncryption();
        String plaintext = "This should compress pretty good, it should, yes it should pretty good it should it should";
        jwe.setPlaintext(plaintext);
        AesKey key = new AesKey(new byte[32]);
        jwe.setKey(key);
        jwe.setHeader(HeaderParameterNames.ZIP, "bad");
        jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
        jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
View Full Code Here

                "{\"kty\":\"oct\",\n" +
                " \"k\":\"GawgguFyGrWKav7AX4VKUg\"\n" +
                "}");

        jwe.setCompactSerialization(jweCsFromAppdxA3);
        jwe.setKey(new AesKey(jsonWebKey.getKey().getEncoded()));

        String plaintextString = jwe.getPlaintextString();

        assertEquals("Live long and prosper.", plaintextString);
    }
View Full Code Here

    }

    private AesKey aesKey(int byteLength)
    {
        return new AesKey(new byte[byteLength]);
    }
View Full Code Here

    @Test
    public void testLeadingAndTrailingZeros() throws JoseException
    {
        byte[] rawInputBytes = new byte[] {0,0,111,16,51,98,-4,0,-72,9,-111,60,41,-66,94,0};
        JsonWebKey jwk = JsonWebKey.Factory.newJwk(new AesKey(rawInputBytes));
        String json = jwk.toJson(INCLUDE_SYMMETRIC);

        JsonWebKey jwkFromJson = JsonWebKey.Factory.newJwk(json);
        byte[] encoded = jwkFromJson.getKey().getEncoded();
        assertThat(rawInputBytes.length, is(equalTo(encoded.length)));
View Full Code Here

TOP

Related Classes of org.jose4j.keys.AesKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.