Examples of Base64Url


Examples of org.jose4j.base64url.Base64Url

    @Override
    public ContentEncryptionKeys manageForEncrypt(Key managementKey, ContentEncryptionKeyDescriptor cekDesc, Headers headers, byte[] cekOverride) throws JoseException
    {
        byte[] cek = (cekOverride == null) ? ByteUtil.randomBytes(cekDesc.getContentEncryptionKeyByteLength()) : cekOverride;

        Base64Url base64Url = new Base64Url();

        String encodedIv = headers.getStringHeaderValue(HeaderParameterNames.INITIALIZATION_VECTOR);
        byte[] iv;
        if (encodedIv == null)
        {
            iv = ByteUtil.randomBytes(IV_BYTE_LENGTH);
            encodedIv = base64Url.base64UrlEncode(iv);
            headers.setStringHeaderValue(HeaderParameterNames.INITIALIZATION_VECTOR, encodedIv);
        }
        else
        {
            iv = base64Url.base64UrlDecode(encodedIv);
        }

        SimpleAeadCipher.CipherOutput encrypted = simpleAeadCipher.encrypt(managementKey, iv, cek, null);
        byte[] encryptedKey = encrypted.getCiphertext();
        byte[] tag = encrypted.getTag();

        String encodedTag = base64Url.base64UrlEncode(tag);
        headers.setStringHeaderValue(HeaderParameterNames.AUTHENTICATION_TAG, encodedTag);

        return new ContentEncryptionKeys(cek, encryptedKey);
    }
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

    }

    @Override
    public Key manageForDecrypt(Key managementKey, byte[] encryptedKey, ContentEncryptionKeyDescriptor cekDesc, Headers headers) throws JoseException
    {
        Base64Url base64Url = new Base64Url();
        String encodedIv = headers.getStringHeaderValue(HeaderParameterNames.INITIALIZATION_VECTOR);
        byte[] iv = base64Url.base64UrlDecode(encodedIv);

        String encodedTag = headers.getStringHeaderValue(HeaderParameterNames.AUTHENTICATION_TAG);
        byte[] tag = base64Url.base64UrlDecode(encodedTag);

        byte[] cek = simpleAeadCipher.decrypt(managementKey, iv, encryptedKey, tag, null);
        return new SecretKeySpec(cek, cekDesc.getContentEncryptionKeyAlgorithm());
    }
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

        return gen.randomBytes(length);
    }

    public static String toDebugString(byte[] bytes)
    {
        Base64Url base64Url = new Base64Url();
        String s = base64Url.base64UrlEncode(bytes);
        int[] ints = convertSignedTwosCompToUnsigned(bytes);
        return Arrays.toString(ints) + "("+ints.length+"bytes/"+bitLength(ints.length)+"bits) | base64url encoded: " + s;
    }
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

        return new BigInteger(1, magnitude);
    }

    public static BigInteger fromBase64Url(String base64urlEncodedBytes)
    {
        Base64Url base64Url = new Base64Url();
        byte[] magnitude = base64Url.base64UrlDecode(base64urlEncodedBytes);
        return fromBytes(magnitude);
    }
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

        return magnitude;
    }

    public static String toBase64Url(BigInteger bigInteger)
    {
        Base64Url base64Url = new Base64Url();
        byte[] bytes = toByteArray(bigInteger);
        return base64Url.base64UrlEncode(bytes);
    }
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

        return base64Url.base64UrlEncode(bytes);
    }

    public static String toBase64Url(BigInteger bigInteger, int minByteArrayLength)
    {
        Base64Url base64Url = new Base64Url();
        byte[] bytes = toByteArray(bigInteger, minByteArrayLength);
        return base64Url.base64UrlEncode(bytes);
    }
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

        byte[] calculatedAuthenticationTag = mac.doFinal(authenticationTagInput);
        calculatedAuthenticationTag = ByteUtil.subArray(calculatedAuthenticationTag, 0, getTagTruncationLength()); // truncate it
        boolean tagMatch = ByteUtil.secureEquals(authenticationTag, calculatedAuthenticationTag);
        if (!tagMatch)
        {
            Base64Url base64Url = new Base64Url();
            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));
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

                "     }";
        Map<String, Object> parsed = JsonUtil.parseJson(jwkJson);
        JsonWebKey jsonWebKey = JsonWebKey.Factory.newJwk(parsed);
        assertTrue(jsonWebKey.getKey().equals(ExampleRsaKeyFromJws.PUBLIC_KEY));
        String d = (String)parsed.get("d");
        Base64Url base64Url = new Base64Url();
        byte[] privateExp = base64Url.base64UrlDecode(d);
        assertTrue(Arrays.equals(ExampleRsaKeyFromJws.D_SIGNED_BYTES, privateExp));
    }
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

        ContentEncryptionKeys contentEncryptionKeys = wrappingKeyManagementAlgorithm.manageForEnc(managementKey, cekDesc, cekBytes);

        String encodedEncryptedKeyFromExample ="6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ";

        Base64Url u = new Base64Url();
        String encodedWrapped = u.base64UrlEncode(contentEncryptionKeys.getEncryptedKey());

        assertEquals(encodedEncryptedKeyFromExample, encodedWrapped);

        byte[] encryptedKey = u.base64UrlDecode(encodedEncryptedKeyFromExample);

        Key key = wrappingKeyManagementAlgorithm.manageForDecrypt(managementKey, encryptedKey, cekDesc, null);

        assertTrue(Arrays.equals(cekBytes, key.getEncoded()));
    }
View Full Code Here

Examples of org.jose4j.base64url.Base64Url

        PublicKey pubKey = receiverJwk.getPublicKey();
        ContentEncryptionKeys contentEncryptionKeys = ecdhKeyAgreementAlgorithm.manageForEncrypt(pubKey, cekDesc, headers, ephemeralJwk);

        assertTrue(contentEncryptionKeys.getEncryptedKey().length == 0);
        Base64Url base64Url = new Base64Url();
        assertEquals("VqqN6vgjbSBcIijNcacQGg", base64Url.base64UrlEncode(contentEncryptionKeys.getContentEncryptionKey()));

        Headers receivedHeaders = new Headers();
        receivedHeaders.setFullHeaderAsJsonString(headers.getFullHeaderAsJsonString());

        Key key = ecdhKeyAgreementAlgorithm.manageForDecrypt(receiverJwk.getPrivateKey(), null, cekDesc, receivedHeaders);
        assertEquals("VqqN6vgjbSBcIijNcacQGg", base64Url.base64UrlEncode(key.getEncoded()));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.