本文整理汇总了Java中org.jose4j.base64url.Base64Url.base64UrlDecode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64Url.base64UrlDecode方法的具体用法?Java Base64Url.base64UrlDecode怎么用?Java Base64Url.base64UrlDecode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jose4j.base64url.Base64Url
的用法示例。
在下文中一共展示了Base64Url.base64UrlDecode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deriveForEncrypt
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
protected Key deriveForEncrypt(Key managementKey, Headers headers, ProviderContext providerContext) throws JoseException
{
Long iterationCount = headers.getLongHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT);
if (iterationCount == null)
{
iterationCount = defaultIterationCount;
headers.setObjectHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT, iterationCount);
}
String saltInputString = headers.getStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT);
byte[] saltInput;
Base64Url base64Url = new Base64Url();
if (saltInputString == null)
{
saltInput = ByteUtil.randomBytes(defaultSaltByteLength, providerContext.getSecureRandom());
saltInputString = base64Url.base64UrlEncode(saltInput);
headers.setStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT, saltInputString);
}
else
{
saltInput = base64Url.base64UrlDecode(saltInputString);
}
return deriveKey(managementKey, iterationCount, saltInput, providerContext);
}
示例2: testExampleDecryptFromJweAppendix2
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public void testExampleDecryptFromJweAppendix2() throws JoseException
{
int[] ints = {4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106, 206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156, 44, 207};
byte[] contentEncryptionKeyBytes = ByteUtil.convertUnsignedToSignedTwosComp(ints);
Base64Url b = new Base64Url();
String encodedHeader = "eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0";
Headers headers = new Headers();
headers.setFullHeaderAsJsonString(Base64Url.decodeToUtf8String(encodedHeader));
byte[] header = StringUtil.getBytesUtf8(encodedHeader);
byte[] iv = b.base64UrlDecode("AxY8DCtDaGlsbGljb3RoZQ");
byte[] ciphertext = b.base64UrlDecode("KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY");
byte[] tag = b.base64UrlDecode("9hH0vgRfYgPnAHOd8stkvw");
AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256 jweContentEncryptionAlg = new AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256();
ContentEncryptionParts encryptionParts = new ContentEncryptionParts(iv, ciphertext, tag);
byte[] plaintextBytes = jweContentEncryptionAlg.decrypt(encryptionParts, header, contentEncryptionKeyBytes, headers, ProviderContextTest.EMPTY_CONTEXT);
assertEquals("Live long and prosper.", StringUtil.newStringUtf8(plaintextBytes));
}
示例3: testDefaultsMeetMinimumRequiredOrSuggested
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
@Test
public void testDefaultsMeetMinimumRequiredOrSuggested() throws JoseException
{
JsonWebEncryption encryptingJwe = new JsonWebEncryption();
encryptingJwe.setAlgorithmHeaderValue(PBES2_HS256_A128KW);
encryptingJwe.setEncryptionMethodHeaderParameter(AES_128_CBC_HMAC_SHA_256);
encryptingJwe.setPayload("meh");
PbkdfKey key = new PbkdfKey("passtheword");
encryptingJwe.setKey(key);
String compactSerialization = encryptingJwe.getCompactSerialization();
System.out.println(compactSerialization);
JsonWebEncryption decryptingJwe = new JsonWebEncryption();
decryptingJwe.setCompactSerialization(compactSerialization);
decryptingJwe.setKey(key);
decryptingJwe.getPayload();
Headers headers = decryptingJwe.getHeaders();
Long iterationCount = headers.getLongHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT);
assertTrue(iterationCount >= MINIMUM_ITERAION_COUNT);
String saltInputString = headers.getStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT);
Base64Url b = new Base64Url();
byte[] saltInput = b.base64UrlDecode(saltInputString);
assertTrue(saltInput.length >= MINIMUM_SALT_BYTE_LENGTH);
}
示例4: testJweExampleA2
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public void testJweExampleA2() throws JoseException
{
String encodedEncryptedKey =
"UGhIOguC7IuEvf_NPVaXsGMoLOmwvc1GyqlIKOK1nN94nHPoltGRhWhw7Zx0-kFm" +
"1NJn8LE9XShH59_i8J0PH5ZZyNfGy2xGdULU7sHNF6Gp2vPLgNZ__deLKxGHZ7Pc" +
"HALUzoOegEI-8E66jX2E4zyJKx-YxzZIItRzC5hlRirb6Y5Cl_p-ko3YvkkysZIF" +
"NPccxRU7qve1WYPxqbb2Yw8kZqa2rMWI5ng8OtvzlV7elprCbuPhcCdZ6XDP0_F8" +
"rkXds2vE4X-ncOIM8hAYHHi29NX0mcKiRaD0-D-ljQTP-cFPgwCp6X-nZZd9OHBv" +
"-B3oWh2TbqmScqXMR4gp_A";
Base64Url base64Url = new Base64Url();
byte[] encryptedKey = base64Url.base64UrlDecode(encodedEncryptedKey);
RsaKeyManagementAlgorithm.Rsa1_5 keyManagementAlgorithm = new RsaKeyManagementAlgorithm.Rsa1_5();
PrivateKey privateKey = ExampleRsaJwksFromJwe.APPENDIX_A_2.getPrivateKey();
ContentEncryptionAlgorithm contentEncryptionAlgorithm = new AesCbcHmacSha2ContentEncryptionAlgorithm.Aes128CbcHmacSha256();
ContentEncryptionKeyDescriptor cekDesc = contentEncryptionAlgorithm.getContentEncryptionKeyDescriptor();
Key key = keyManagementAlgorithm.manageForDecrypt(privateKey, encryptedKey, cekDesc, null, ProviderContextTest.EMPTY_CONTEXT);
byte[] cekBytes = ByteUtil.convertUnsignedToSignedTwosComp(new int[]{4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106,
206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156,
44, 207});
byte[] encoded = key.getEncoded();
assertTrue(Arrays.toString(encoded), Arrays.equals(cekBytes, encoded));
}
示例5: OctetSequenceJsonWebKey
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public OctetSequenceJsonWebKey(Map<String, Object> params) throws JoseException
{
super(params);
Base64Url base64Url = new Base64Url();
String b64KeyBytes = getStringRequired(params, KEY_VALUE_MEMBER_NAME);
octetSequence = base64Url.base64UrlDecode(b64KeyBytes);
// um... how could I know the alg? I don't see a reliable way to know.
// Maybe infer from the alg parameter but it's optional.
// Currently it's really either AES or HMAC and only the AES algorithm
// implementations seem to actually care. So I'm gonna just go w/ AES for now.
String alg = AesKey.ALGORITHM;
key = new SecretKeySpec(octetSequence, alg);
}
示例6: manageForEncrypt
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
@Override
public ContentEncryptionKeys manageForEncrypt(Key managementKey, ContentEncryptionKeyDescriptor cekDesc, Headers headers, byte[] cekOverride, ProviderContext providerContext) throws JoseException
{
SecureRandom secureRandom = providerContext.getSecureRandom();
byte[] cek = (cekOverride == null) ? ByteUtil.randomBytes(cekDesc.getContentEncryptionKeyByteLength(), secureRandom) : cekOverride;
Base64Url base64Url = new Base64Url();
String encodedIv = headers.getStringHeaderValue(HeaderParameterNames.INITIALIZATION_VECTOR);
byte[] iv;
if (encodedIv == null)
{
iv = ByteUtil.randomBytes(IV_BYTE_LENGTH, secureRandom);
encodedIv = base64Url.base64UrlEncode(iv);
headers.setStringHeaderValue(HeaderParameterNames.INITIALIZATION_VECTOR, encodedIv);
}
else
{
iv = base64Url.base64UrlDecode(encodedIv);
}
String cipherProvider = providerContext.getSuppliedKeyProviderContext().getCipherProvider();
SimpleAeadCipher.CipherOutput encrypted = simpleAeadCipher.encrypt(managementKey, iv, cek, null, cipherProvider);
byte[] encryptedKey = encrypted.getCiphertext();
byte[] tag = encrypted.getTag();
String encodedTag = base64Url.base64UrlEncode(tag);
headers.setStringHeaderValue(HeaderParameterNames.AUTHENTICATION_TAG, encodedTag);
return new ContentEncryptionKeys(cek, encryptedKey);
}
示例7: manageForDecrypt
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
@Override
public Key manageForDecrypt(Key managementKey, byte[] encryptedKey, ContentEncryptionKeyDescriptor cekDesc, Headers headers, ProviderContext providerContext) 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);
String cipherProvider = providerContext.getSuppliedKeyProviderContext().getCipherProvider();
byte[] cek = simpleAeadCipher.decrypt(managementKey, iv, encryptedKey, tag, null, cipherProvider);
return new SecretKeySpec(cek, cekDesc.getContentEncryptionKeyAlgorithm());
}
示例8: manageForDecrypt
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
@Override
public Key manageForDecrypt(Key managementKey, byte[] encryptedKey, ContentEncryptionKeyDescriptor cekDesc, Headers headers, ProviderContext providerContext) throws JoseException
{
Long iterationCount = headers.getLongHeaderValue(HeaderParameterNames.PBES2_ITERATION_COUNT);
String saltInputString = headers.getStringHeaderValue(HeaderParameterNames.PBES2_SALT_INPUT);
Base64Url base64Url = new Base64Url();
byte[] saltInput = base64Url.base64UrlDecode(saltInputString);
Key derivedKey = deriveKey(managementKey, iterationCount, saltInput, providerContext);
return keyWrap.manageForDecrypt(derivedKey, encryptedKey, cekDesc, headers, providerContext);
}
示例9: testCryptoBinaryThread
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
@Test
public void testCryptoBinaryThread() throws Exception
{
// make sure that "The length of [the y] octet string MUST
// be the full size of a coordinate for the curve specified in the "crv"
// parameter."
String keySpec = "MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBCCAc9n4N7ZOr_tTu" +
"_wAOmPKi4qTp5X3su6O3010hxmBYj9zI4u_0dm6UZa0LsjdfvcAET6vH3mEApvGKpDWrRsAA_nJhyQ20ca7Nn0Zvyiq54FfCAblGK7kuduF" +
"BTPkxv9eOjiaeGp7V_f3qV1kxS_Il2LY7Tc5l2GSlW_-SzYKxgek";
Base64Url base64Url = new Base64Url();
byte[] bytes = base64Url.base64UrlDecode(keySpec);
PublicKey ecPubKey = KeyFactory.getInstance("EC").generatePublic(new X509EncodedKeySpec(bytes));
PublicJsonWebKey jwk = EllipticCurveJsonWebKey.Factory.newPublicJwk(ecPubKey);
String jwkJson = jwk.toJson(PUBLIC_ONLY);
Map<String,Object> parsed = JsonUtil.parseJson(jwkJson);
String x = (String)parsed.get(EllipticCurveJsonWebKey.X_MEMBER_NAME);
assertThat("AQggHPZ-De2Tq_7U7v8ADpjyouKk6eV97Lujt9NdIcZgWI_cyOLv9HZulGWtC7I3X73ABE-rx95hAKbxiqQ1q0bA", is(equalTo(x)));
String y = (String)parsed.get(EllipticCurveJsonWebKey.Y_MEMBER_NAME);
assertThat("AP5yYckNtHGuzZ9Gb8oqueBXwgG5Riu5LnbhQUz5Mb_Xjo4mnhqe1f396ldZMUvyJdi2O03OZdhkpVv_ks2CsYHp", is(equalTo(y)));
// we will be liberal and accept either
String noLeftZeroPaddingBytes = "{\"kty\":\"EC\",\"x\":\"AQggHPZ-De2Tq_7U7v8ADpjyouKk6eV97Lujt9NdIcZgWI_cyOLv9HZulGWtC7I3X73ABE-rx95hAKbxiqQ1q0bA\",\"y\":\"_nJhyQ20ca7Nn0Zvyiq54FfCAblGK7kuduFBTPkxv9eOjiaeGp7V_f3qV1kxS_Il2LY7Tc5l2GSlW_-SzYKxgek\",\"crv\":\"P-521\"}";
String withLeftZeroPaddingBytes = "{\"kty\":\"EC\",\"x\":\"AQggHPZ-De2Tq_7U7v8ADpjyouKk6eV97Lujt9NdIcZgWI_cyOLv9HZulGWtC7I3X73ABE-rx95hAKbxiqQ1q0bA\",\"y\":\"AP5yYckNtHGuzZ9Gb8oqueBXwgG5Riu5LnbhQUz5Mb_Xjo4mnhqe1f396ldZMUvyJdi2O03OZdhkpVv_ks2CsYHp\",\"crv\":\"P-521\"}";
PublicJsonWebKey jwkWithNoZeroLeftPaddingBytes = EllipticCurveJsonWebKey.Factory.newPublicJwk(noLeftZeroPaddingBytes);
PublicJsonWebKey jwkWithZeroLeftPaddingBytes = EllipticCurveJsonWebKey.Factory.newPublicJwk(withLeftZeroPaddingBytes);
assertEquals(jwkWithNoZeroLeftPaddingBytes.getPublicKey(), jwkWithZeroLeftPaddingBytes.getPublicKey());
}
示例10: testKey11to12
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public void testKey11to12() throws Exception
{
// draft 12 used a JWK encoding of the key where previously it was octet sequences
// and this is just a sanity check that it didn't change and my stuff sees them as the same
// may want to redo some of the ExampleRsaKeyFromJws to just use the JWK serialization at some point
// if private key support is added
String jwkJson = " {\"kty\":\"RSA\",\n" +
" \"n\":\"ofgWCuLjybRlzo0tZWJjNiuSfb4p4fAkd_wWJcyQoTbji9k0l8W26mPddx\n" +
" HmfHQp-Vaw-4qPCJrcS2mJPMEzP1Pt0Bm4d4QlL-yRT-SFd2lZS-pCgNMs\n" +
" D1W_YpRPEwOWvG6b32690r2jZ47soMZo9wGzjb_7OMg0LOL-bSf63kpaSH\n" +
" SXndS5z5rexMdbBYUsLA9e-KXBdQOS-UTo7WTBEMa2R2CapHg665xsmtdV\n" +
" MTBQY4uDZlxvb3qCo5ZwKh9kG4LT6_I5IhlJH7aGhyxXFvUK-DWNmoudF8\n" +
" NAco9_h9iaGNj8q2ethFkMLs91kzk2PAcDTW9gb54h4FRWyuXpoQ\",\n" +
" \"e\":\"AQAB\",\n" +
" \"d\":\"Eq5xpGnNCivDflJsRQBXHx1hdR1k6Ulwe2JZD50LpXyWPEAeP88vLNO97I\n" +
" jlA7_GQ5sLKMgvfTeXZx9SE-7YwVol2NXOoAJe46sui395IW_GO-pWJ1O0\n" +
" BkTGoVEn2bKVRUCgu-GjBVaYLU6f3l9kJfFNS3E0QbVdxzubSu3Mkqzjkn\n" +
" 439X0M_V51gfpRLI9JYanrC4D4qAdGcopV_0ZHHzQlBjudU2QvXt4ehNYT\n" +
" CBr6XCLQUShb1juUO1ZdiYoFaFQT5Tw8bGUl_x_jTj3ccPDVZFD9pIuhLh\n" +
" BOneufuBiB4cS98l2SR_RQyGWSeWjnczT0QU91p1DhOVRuOopznQ\"\n" +
" }";
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));
}
示例11: testJweExample
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public void testJweExample() throws JoseException
{
// Test the AES key wrap part of Example JWE using AES Key Wrap and AES_128_CBC_HMAC_SHA_256 from
// http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-14#appendix-A.3
int[] cekInts = {4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106,
206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156,
44, 207};
byte[] cekBytes = ByteUtil.convertUnsignedToSignedTwosComp(cekInts);
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();
ContentEncryptionKeys contentEncryptionKeys = wrappingKeyManagementAlgorithm.manageForEnc(managementKey, cekDesc, cekBytes, ProviderContextTest.EMPTY_CONTEXT);
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, ProviderContextTest.EMPTY_CONTEXT);
assertTrue(Arrays.equals(cekBytes, key.getEncoded()));
}
示例12: testJweExampleA1
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
@Test
public void testJweExampleA1() throws JoseException
{
// only the key encryption part from
// http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-25#appendix-A.1
String encodedEncryptedKey =
"OKOawDo13gRp2ojaHV7LFpZcgV7T6DVZKTyKOMTYUmKoTCVJRgckCL9kiMT03JGe" +
"ipsEdY3mx_etLbbWSrFr05kLzcSr4qKAq7YN7e9jwQRb23nfa6c9d-StnImGyFDb" +
"Sv04uVuxIp5Zms1gNxKKK2Da14B8S4rzVRltdYwam_lDp5XnZAYpQdb76FdIKLaV" +
"mqgfwX7XWRxv2322i-vDxRfqNzo_tETKzpVLzfiwQyeyPGLBIO56YJ7eObdv0je8" +
"1860ppamavo35UgoRdbYaBcoh9QcfylQr66oc6vFWXRcZ_ZT2LawVCWTIy3brGPi" +
"6UklfCpIMfIjf7iGdXKHzg";
Base64Url base64Url = new Base64Url();
byte[] encryptedKey = base64Url.base64UrlDecode(encodedEncryptedKey);
RsaKeyManagementAlgorithm.RsaOaep keyManagementAlgorithm = new RsaKeyManagementAlgorithm.RsaOaep();
PrivateKey privateKey = ExampleRsaJwksFromJwe.APPENDIX_A_1.getPrivateKey();
ContentEncryptionKeyDescriptor cekDesc = new ContentEncryptionKeyDescriptor(32, AesKey.ALGORITHM);
Key key = keyManagementAlgorithm.manageForDecrypt(privateKey, encryptedKey, cekDesc, null, ProviderContextTest.EMPTY_CONTEXT);
byte[] cekBytes = ByteUtil.convertUnsignedToSignedTwosComp(new int[]{177, 161, 244, 128, 84, 143, 225,
115, 63, 180, 3, 255, 107, 154, 212, 246, 138, 7, 110, 91, 112, 46, 34, 105, 47, 130, 203, 46,
122, 234, 64, 252});
byte[] encoded = key.getEncoded();
assertTrue(Arrays.toString(encoded), Arrays.equals(cekBytes, encoded));
}
示例13: fromBase64Url
import org.jose4j.base64url.Base64Url; //导入方法依赖的package包/类
public static BigInteger fromBase64Url(String base64urlEncodedBytes)
{
Base64Url base64Url = new Base64Url();
byte[] magnitude = base64Url.base64UrlDecode(base64urlEncodedBytes);
return fromBytes(magnitude);
}