当前位置: 首页>>代码示例>>Java>>正文


Java AesKey类代码示例

本文整理汇总了Java中org.jose4j.keys.AesKey的典型用法代码示例。如果您正苦于以下问题:Java AesKey类的具体用法?Java AesKey怎么用?Java AesKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AesKey类属于org.jose4j.keys包,在下文中一共展示了AesKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createJWT

import org.jose4j.keys.AesKey; //导入依赖的package包/类
/**
 * Encrypt the otp to be send via mail
 */
@Override
public String createJWT(String userid, long ttlMillis) {
  Key key = new AesKey(ConfigUtil.get(JWTKEY).getBytes());
  JsonWebEncryption jwe = new JsonWebEncryption();
  jwe.setKey(key);
  jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
  jwe.setEncryptionMethodHeaderParameter(
      ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
  jwe.setPayload(userid + "&&" + ttlMillis);
  try {
    return jwe.getCompactSerialization();
  } catch (JoseException e) {
    xLogger.warn("Unable to get the jwt service: {0}", e.getMessage());
  }
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:20,代码来源:AuthenticationServiceImpl.java

示例2: DefaultCipherExecutor

import org.jose4j.keys.AesKey; //导入依赖的package包/类
/**
 * Instantiates a new cipher.
 *
 * @param secretKeyEncryption the key for encryption
 * @param secretKeySigning the key for signing
 * @param contentEncryptionAlgorithmIdentifier the content encryption algorithm identifier
 * @param signingAlgorithm the signing algorithm
 */
public DefaultCipherExecutor(final String secretKeyEncryption,
                             final String secretKeySigning,
                             final String contentEncryptionAlgorithmIdentifier,
                             final String signingAlgorithm) {
    this.secretKeyEncryptionKey =  prepareJsonWebTokenKey(secretKeyEncryption);
    this.contentEncryptionAlgorithmIdentifier = contentEncryptionAlgorithmIdentifier;

    logger.debug("Initialized cipher encryption sequence via [{}]",
             contentEncryptionAlgorithmIdentifier);

    this.signingAlgorithm = signingAlgorithm;
    this.secretKeySigningKey = new AesKey(secretKeySigning.getBytes());

    logger.debug("Initialized cipher signing sequence via [{}]",
            signingAlgorithm);

}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:26,代码来源:DefaultCipherExecutor.java

示例3: decryptJWT

import org.jose4j.keys.AesKey; //导入依赖的package包/类
/**
 * Decrypt the otp received via mail
 */
@Override
public String decryptJWT(String token) {
  JsonWebEncryption jwe = new JsonWebEncryption();
  Key key = new AesKey(ConfigUtil.get(JWTKEY).getBytes());
  jwe.setKey(key);
  jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
  jwe.setEncryptionMethodHeaderParameter(
      ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
  try {
    jwe.setCompactSerialization(token);
    return jwe.getPayload();
  } catch (JoseException e) {
    xLogger.warn("Unable to get the jwt service: {0}", e.getMessage());
  }
  jwe.setKey(key);
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:AuthenticationServiceImpl.java

示例4: validateAesWrappingKey

import org.jose4j.keys.AesKey; //导入依赖的package包/类
public static void validateAesWrappingKey(Key managementKey, String joseAlg, int expectedKeyByteLength) throws InvalidKeyException
{
    KeyValidationSupport.notNull(managementKey);

    String alg = managementKey.getAlgorithm();

    if (!AesKey.ALGORITHM.equals(alg))
    {
        throw new InvalidKeyException("Invalid key for JWE " + joseAlg + ", expected an "
                + AesKey.ALGORITHM+ " key but an " + alg + " key was provided.");
    }

    if (managementKey.getEncoded() != null)
    {
        int managementKeyByteLength = managementKey.getEncoded().length;
        if (managementKeyByteLength != expectedKeyByteLength)
        {
            throw new InvalidKeyException("Invalid key for JWE " + joseAlg + ", expected a "
                    + ByteUtil.bitLength(expectedKeyByteLength)+ " bit key but a "
                    + ByteUtil.bitLength(managementKeyByteLength) + " bit key was provided.");
        }
    }
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:24,代码来源:KeyValidationSupport.java

示例5: testJweExampleA3

import org.jose4j.keys.AesKey; //导入依赖的package包/类
@Test
public void testJweExampleA3() throws JoseException
{
    // http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-14#appendix-A.3
    String jweCsFromAppdxA3 = "eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0." +
            "6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ." +
            "AxY8DCtDaGlsbGljb3RoZQ." +
            "KDlTtXchhZTGufMYmOYGS4HffxPSUrfmqCHXaI9wOGY." +
            "U0m_YmjN04DJvceFICbCVQ";

    JsonWebEncryption jwe = new JsonWebEncryption();
    JsonWebKey jsonWebKey = JsonWebKey.Factory.newJwk("\n" +
            "{\"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);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:24,代码来源:JsonWebEncryptionTest.java

示例6: testRoundTrip

import org.jose4j.keys.AesKey; //导入依赖的package包/类
@Test
public void testRoundTrip() throws JoseException
{
    RsaKeyManagementAlgorithm.RsaOaep oaep = new RsaKeyManagementAlgorithm.RsaOaep();
    ContentEncryptionKeyDescriptor cekDesc = new ContentEncryptionKeyDescriptor(16, AesKey.ALGORITHM);
    PublicKey publicKey = ExampleRsaJwksFromJwe.APPENDIX_A_1.getPublicKey();
    ContentEncryptionKeys contentEncryptionKeys = oaep.manageForEncrypt(publicKey, cekDesc, null, null, ProviderContextTest.EMPTY_CONTEXT);

    byte[] encryptedKey = contentEncryptionKeys.getEncryptedKey();

    PrivateKey privateKey = ExampleRsaJwksFromJwe.APPENDIX_A_1.getPrivateKey();
    Key key = oaep.manageForDecrypt(privateKey, encryptedKey, cekDesc, null, ProviderContextTest.EMPTY_CONTEXT);

    byte[] cek = contentEncryptionKeys.getContentEncryptionKey();
    assertTrue(Arrays.equals(cek, key.getEncoded()));
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:17,代码来源:RsaOaepKeyManagementAlgorithmTest.java

示例7: testJweBadZipValueProduce

import org.jose4j.keys.AesKey; //导入依赖的package包/类
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.setCompressionAlgorithmHeaderParameter("bad");
    jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.DIRECT);
    jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);

    try
    {
        String cs = jwe.getCompactSerialization();
        fail("Should fail with invalid zip header value: " + cs);
    }
    catch (InvalidAlgorithmException e)
    {
        // just see if the exception message says something about the header name
        assertTrue(e.getMessage().contains(HeaderParameterNames.ZIP));
    }
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:23,代码来源:ZipTest.java

示例8: getJwsCompactSerialization

import org.jose4j.keys.AesKey; //导入依赖的package包/类
@Override
public String getJwsCompactSerialization(String payload, byte[] secretKey) {
    try {
        Key key = new AesKey(secretKey);

        JsonWebSignature jws = new JsonWebSignature();
        jws.setPayload(payload);
        jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
        jws.setKey(key);
        String jwsCompactSerialization = jws.getCompactSerialization();

        return jwsCompactSerialization;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
开发者ID:ix3,项目名称:ix3,代码行数:17,代码来源:JwsImplJose4j.java

示例9: verifyJwsCompactSerialization

import org.jose4j.keys.AesKey; //导入依赖的package包/类
@Override
public boolean verifyJwsCompactSerialization(String jwsCompactSerialization, byte[] secretKey) {
    try {        
        Key key = new AesKey(secretKey);
        JsonWebSignature jws = new JsonWebSignature();
        jws.setCompactSerialization(jwsCompactSerialization);
        jws.setKey(key);

        boolean signatureVerified = jws.verifySignature();
        
        return signatureVerified;
        
    } catch (JoseException ex) {
        throw new RuntimeException(ex);
    }            
}
 
开发者ID:ix3,项目名称:ix3,代码行数:17,代码来源:JwsImplJose4j.java

示例10: aesEncryptDecrypt128

import org.jose4j.keys.AesKey; //导入依赖的package包/类
@Test
public void aesEncryptDecrypt128() throws Exception {

    String keyText = "iue98623diDEs096";
    String data = "I am marico";
    Key key = new AesKey(keyText.getBytes());

    //加密
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
    jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
    jwe.setKey(key);
    jwe.setPayload(data);

    String idToken = jwe.getCompactSerialization();
    assertNotNull(idToken);
    System.out.println(data + " idToken: " + idToken);

    //解密
    JsonWebEncryption jwe2 = new JsonWebEncryption();
    jwe2.setKey(key);
    jwe2.setCompactSerialization(idToken);

    final String payload = jwe2.getPayload();
    assertNotNull(payload);
    assertEquals(payload, data);

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:29,代码来源:Jose4JTest.java

示例11: aesEncryptDecrypt256

import org.jose4j.keys.AesKey; //导入依赖的package包/类
@Test
public void aesEncryptDecrypt256() throws Exception {

    String keyText = "[email protected](*JKse09";
    String data = "I am marico";
    Key key = new AesKey(keyText.getBytes());

    //加密
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A256KW);
    jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_256_CBC_HMAC_SHA_512);
    jwe.setKey(key);
    jwe.setPayload(data);

    String idToken = jwe.getCompactSerialization();
    assertNotNull(idToken);
    System.out.println(data + " idToken: " + idToken);

    //解密
    JsonWebEncryption jwe2 = new JsonWebEncryption();
    jwe2.setKey(key);
    jwe2.setCompactSerialization(idToken);

    final String payload = jwe2.getPayload();
    assertNotNull(payload);
    assertEquals(payload, data);

}
 
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:29,代码来源:Jose4JTest.java

示例12: OctetSequenceJsonWebKey

import org.jose4j.keys.AesKey; //导入依赖的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);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:14,代码来源:OctetSequenceJsonWebKey.java

示例13: AesCbcHmacSha2ContentEncryptionAlgorithm

import org.jose4j.keys.AesKey; //导入依赖的package包/类
public AesCbcHmacSha2ContentEncryptionAlgorithm(String alg, int cekByteLen, String javaHmacAlg, int tagTruncationLength)
{
    setAlgorithmIdentifier(alg);
    contentEncryptionKeyDescriptor = new ContentEncryptionKeyDescriptor(cekByteLen, AesKey.ALGORITHM);
    this.hmacJavaAlgorithm = javaHmacAlg;
    this.tagTruncationLength = tagTruncationLength;

    // This actually ends up with a cipher that does AES/CBC/PKCS7Padding but the JCA wants PKCS5Padding in the name
    // A thread on it in the JOSE WG at http://www.ietf.org/mail-archive/web/jose/current/msg05031.html
    setJavaAlgorithm("AES/CBC/PKCS5Padding");

    setKeyPersuasion(KeyPersuasion.SYMMETRIC);
    setKeyType(AesKey.ALGORITHM);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:15,代码来源:AesCbcHmacSha2ContentEncryptionAlgorithm.java

示例14: EcdhKeyAgreementWithAesKeyWrapAlgorithm

import org.jose4j.keys.AesKey; //导入依赖的package包/类
public EcdhKeyAgreementWithAesKeyWrapAlgorithm(String alg, AesKeyWrapManagementAlgorithm keyWrapAlgorithm)
{
    setAlgorithmIdentifier(alg);
    setJavaAlgorithm("N/A");
    setKeyType(EllipticCurveJsonWebKey.KEY_TYPE);
    setKeyPersuasion(KeyPersuasion.ASYMMETRIC);
    this.keyWrap = keyWrapAlgorithm;
    this.ecdh = new EcdhKeyAgreementAlgorithm(HeaderParameterNames.ALGORITHM);
    keyWrapKeyDescriptor = new ContentEncryptionKeyDescriptor(keyWrapAlgorithm.getKeyByteLength(), AesKey.ALGORITHM);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:11,代码来源:EcdhKeyAgreementWithAesKeyWrapAlgorithm.java

示例15: Pbes2HmacShaWithAesKeyWrapAlgorithm

import org.jose4j.keys.AesKey; //导入依赖的package包/类
public Pbes2HmacShaWithAesKeyWrapAlgorithm(String alg, String hmacAlg, AesKeyWrapManagementAlgorithm keyWrapAlg)
{
    setAlgorithmIdentifier(alg);
    setJavaAlgorithm("n/a");
    pbkdf2 = new PasswordBasedKeyDerivationFunction2(hmacAlg);
    setKeyPersuasion(KeyPersuasion.SYMMETRIC);
    setKeyType(PbkdfKey.ALGORITHM);
    keyWrap = keyWrapAlg;
    keyWrapKeyDescriptor = new ContentEncryptionKeyDescriptor(keyWrap.getKeyByteLength(), AesKey.ALGORITHM);
}
 
开发者ID:RbkGh,项目名称:Jose4j,代码行数:11,代码来源:Pbes2HmacShaWithAesKeyWrapAlgorithm.java


注:本文中的org.jose4j.keys.AesKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。