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


Java Association.createHmacSha256方法代码示例

本文整理汇总了Java中org.openid4java.association.Association.createHmacSha256方法的典型用法代码示例。如果您正苦于以下问题:Java Association.createHmacSha256方法的具体用法?Java Association.createHmacSha256怎么用?Java Association.createHmacSha256使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openid4java.association.Association的用法示例。


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

示例1: load

import org.openid4java.association.Association; //导入方法依赖的package包/类
@Override
    public Association load(String handle) {

        if(IdentityUtil.isBlank(handle)){
            throw new IllegalArgumentException("Handle is empty");
        }
        if(log.isDebugEnabled()){
            log.debug("Inside load(); handle : " + handle);
        }
        String timeStamp = handle.substring((Integer.toString(storeId)).length(), handle.indexOf("-"));
        Date expireDate = new Date(Long.parseLong(timeStamp)+ this.expireIn);
        if(log.isDebugEnabled()){
            log.debug("Calculated Expiry Time : " + expireDate.getTime());
        }
//        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
//        PBEKeySpec spec = new PBEKeySpec(serverKey.toCharArray(), handle.getBytes(), 1, 256);
//        SecretKey secretKey = factory.generateSecret(spec);

        return Association.createHmacSha256(handle, (serverKey + handle).getBytes(), expireDate);
    }
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:21,代码来源:PrivateAssociationCryptoStore.java

示例2: mapToAssociation

import org.openid4java.association.Association; //导入方法依赖的package包/类
private Association mapToAssociation(OpenIdAssociation ssoAssociation) {
    Association association;

    String type = ssoAssociation.getType();
    String handle = ssoAssociation.getHandle();
    byte[] macKey = ssoAssociation.getKey();
    DateTime expiration = ssoAssociation.getExpiry();

    switch(type) {
        case Association.TYPE_HMAC_SHA1:
            association = Association.createHmacSha1(handle, macKey, expiration.toDate());
            break;
        case Association.TYPE_HMAC_SHA256:
            association = Association.createHmacSha256(handle, macKey, expiration.toDate());
            break;
        default:
            LOGGER.warn("Somehow a handle of type {0} managed to get into the persistent store.", type);
            return null;
    }

    return association;
}
 
开发者ID:patka,项目名称:cognitor,代码行数:23,代码来源:AssociationStoreServiceImpl.java

示例3: generate

import org.openid4java.association.Association; //导入方法依赖的package包/类
@Override
    public Association generate(String type, int expiryIn) throws AssociationException {

        if(log.isDebugEnabled()){
            log.debug("Inside generate();  type : " + type + " expiryIn  : " + expiryIn);
        }

        long timestamp = new Date().getTime();
        if(log.isDebugEnabled()){
            log.debug("Current Time : " + timestamp);
        }
        // make time in to millisecond before it is set
        if(this.expireIn == 0){
            this.expireIn = expiryIn * 1000;
        }
        if(log.isDebugEnabled()){
            log.debug("Expires In : " + this.expireIn);
        }
        Date expireDate = new Date(timestamp + this.expireIn);
        if(log.isDebugEnabled()){
            log.debug("Expiry Time : " + expireDate.getTime());
        }

        String handle = Integer.toString(storeId) + Long.toString(timestamp) + "-" + Integer.toString(counter++);

        if(log.isDebugEnabled()){
            log.debug("Handle generated by crypto store : " + handle);
        }

//        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
//        PBEKeySpec spec = new PBEKeySpec(serverKey.toCharArray(), handle.getBytes(), 1, 256);
//        SecretKey secretKey = factory.generateSecret(spec);

        Association association = Association.createHmacSha256(handle, (serverKey + handle).getBytes(), expireDate);
        OpenIDServerManager.setThreadLocalAssociation(association);
        return association;
    }
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:38,代码来源:PrivateAssociationCryptoStore.java

示例4: getAssociation

import org.openid4java.association.Association; //导入方法依赖的package包/类
/**
 * Generates an Association object from an Association Response.
 *
 * @param dhSess        The Diffie-Helman session containing the private key
 *                      used to encrypt / decrypt the MAC key exchange.
 *                      Should be null for no-encryption sessions.
 */
public Association getAssociation(DiffieHellmanSession dhSess)
        throws AssociationException
{
    if (DEBUG) _log.debug("Retrieving MAC key from association response...");

    String handle = getParameterValue("assoc_handle");
    int expiresIn = Integer.parseInt(
            getParameterValue("expires_in") );

    // get (and decrypt) the MAC key
    byte[] macKey;

    AssociationSessionType type = getType();

    if ( type.getHAlgorithm() != null )
    {
        macKey = dhSess.decryptMacKey(
                getParameterValue("enc_mac_key"),
                getParameterValue("dh_server_public") );
        if (DEBUG) _log.debug("Decrypted MAC key (base64): " +
                              new String(Base64.encodeBase64(macKey)));
    }
    else
    {
        macKey = Base64.decodeBase64(
                getParameterValue("mac_key").getBytes() );

        if (DEBUG) _log.debug("Unencrypted MAC key (base64): "
                              + getParameterValue("mac_key"));
    }

    Association assoc;

    if (Association.TYPE_HMAC_SHA1.equals(type.getAssociationType()))
        assoc = Association.createHmacSha1(handle, macKey, expiresIn);

    else if (Association.TYPE_HMAC_SHA256.equals(type.getAssociationType()))
        assoc = Association.createHmacSha256(handle, macKey, expiresIn);

    else
        throw new AssociationException("Unknown association type: " + type);

    if (DEBUG) _log.debug("Created association for handle: " + handle);

    return assoc;
}
 
开发者ID:jbufu,项目名称:openid4java,代码行数:54,代码来源:AssociationResponse.java

示例5: load

import org.openid4java.association.Association; //导入方法依赖的package包/类
public Association load ( String opUrl, String handle )
{		
	try
	{
		JdbcTemplate jdbcTemplate = getJdbcTemplate ( ) ;

		Map res = jdbcTemplate.queryForMap ( _sqlSelect, new Object[]
			{ opUrl, handle } ) ;

		String type = (String) res.get ( "type" ) ;
		String macKey = (String) res.get ( "mackey" ) ;
		Date expDate = (Date) res.get ( "expdate" ) ;

		if ( type == null || macKey == null || expDate == null )
			throw new AssociationException (
												"Invalid association data retrived from database; cannot create Association "
														+ "object for handle: "
														+ handle ) ;

		Association assoc ;

		if ( Association.TYPE_HMAC_SHA1.equals ( type ) )
			assoc = Association.createHmacSha1 (	handle,
													Base64.decodeBase64 ( macKey.getBytes ( ) ),
													expDate ) ;

		else if ( Association.TYPE_HMAC_SHA256.equals ( type ) )
			assoc = Association.createHmacSha256 (	handle,
													Base64.decodeBase64 ( macKey.getBytes ( ) ),
													expDate ) ;

		else
			throw new AssociationException (
												"Invalid association type "
														+ "retrieved from database: "
														+ type ) ;

		if ( _log.isDebugEnabled ( ) )
			_log.debug ( "Retrieved association for handle: " + handle
							+ " from table: " + _tableName ) ;

		return assoc ;
	}
	catch ( AssociationException ase )
	{
		_log.error ( "Error retrieving association from table: "
						+ _tableName, ase ) ;
		return null ;
	}
	catch ( IncorrectResultSizeDataAccessException rse )
	{
		_log.warn ( "Association not found for handle: " + handle
					+ " in the table: " + _tableName ) ;
		return null ;
	}
	catch ( DataAccessException dae )
	{
		_log.error ( "Error retrieving association for handle: " + handle
						+ "from table: " + _tableName, dae ) ;
		return null ;
	}
}
 
开发者ID:jbufu,项目名称:openid4java,代码行数:63,代码来源:JdbcConsumerAssociationStore.java

示例6: load

import org.openid4java.association.Association; //导入方法依赖的package包/类
public Association load(String handle)
{
    try
    {
        String sql = "SELECT type,mackey,expdate FROM " + _tableName +
                " WHERE handle=?";

        JdbcTemplate jdbcTemplate = getJdbcTemplate();

        Map res = jdbcTemplate.queryForMap(sql, new Object[] {handle});

        String type = (String) res.get("type");
        String macKey = (String) res.get("mackey");
        Date expDate = (Date) res.get("expdate");

        if (type == null || macKey == null || expDate == null)
            throw new AssociationException("Invalid association data " +
                    "retrived from database; cannot create Association " +
                    "object for handle: " + handle);

        Association assoc;

        if (Association.TYPE_HMAC_SHA1.equals(type))
            assoc = Association.createHmacSha1(handle,
                    Base64.decodeBase64(macKey.getBytes() ), expDate);

        else if (Association.TYPE_HMAC_SHA256.equals(type))
            assoc = Association.createHmacSha256(handle,
                    Base64.decodeBase64(macKey.getBytes() ), expDate);

        else
            throw new AssociationException("Invalid association type " +
                    "retrieved from database: " + type);

        if (DEBUG)
            _log.debug("Retrieved association for handle: " + handle +
                       " from table: " + _tableName);

        return assoc;
    }
    catch (AssociationException ase )
    {
        _log.error("Error retrieving association from table: " + _tableName, ase);
        return null;
    }
    catch (IncorrectResultSizeDataAccessException rse)
    {
        _log.warn("Association not found for handle: " + handle +
                  " in the table: " + _tableName);
        return null;
    }
    catch (DataAccessException dae)
    {
        _log.error("Error retrieving association for handle: " + handle +
                   "from table: " + _tableName, dae);
        return null;
    }
}
 
开发者ID:jbufu,项目名称:openid4java,代码行数:59,代码来源:JdbcServerAssociationStore.java

示例7: buildAssociationObject

import org.openid4java.association.Association; //导入方法依赖的package包/类
/**
 * Builds the Association object
 *
 * @param results
 * @return <code>Association</code>
 * @throws SQLException
 */
private synchronized Association buildAssociationObject(ResultSet results) {

    Association assoc = null;
    String assocHandle = null;

    try {

        assocHandle = results.getString(1);
        String assocType = results.getString(2);
        java.util.Date expireIn = new java.util.Date(results.getTimestamp(3).getTime());
        String macKey = results.getString(4);
        String assocStore = results.getString(5);

        // we check if params are missing
        if (assocHandle == null || assocType == null || expireIn == null || macKey == null || assocStore == null) {
            log.error("Required data missing. Cannot build the Association object");
            return null;
        }

        // Here we check if we are loading the correct associations
        if (associationStore.equals(OpenIDServerConstants.ASSOCIATION_STORE_TYPE_PRIVATE) &&
            assocStore.equals(OpenIDServerConstants.ASSOCIATION_STORE_TYPE_SHARED)) {
            log.error(
                    "Invalid association data found. Tried to load a Private Association but found a Shared Association");
            return null;
        } else if (associationStore.equals(OpenIDServerConstants.ASSOCIATION_STORE_TYPE_SHARED) &&
                   assocStore.equals(OpenIDServerConstants.ASSOCIATION_STORE_TYPE_PRIVATE)) {
            log.error(
                    "Invalid association data found. Tried to load a Shared Association but found a Private Association");
            return null;
        }

        // Checks for association handle
        if (Association.TYPE_HMAC_SHA1.equals(assocType)) {
            assoc = Association.createHmacSha1(assocHandle, Base64.decode(macKey), expireIn);

        } else if (Association.TYPE_HMAC_SHA256.equals(assocType)) {
            assoc = Association.createHmacSha256(assocHandle, Base64.decode(macKey), expireIn);

        } else {
            log.error("Invalid association type " + assocType + " loaded from database");
            return null;
        }

    } catch (SQLException e) {
        log.error("Failed to build the Association for " + assocHandle + ". Error while accessing the database.",
                  e);
    } finally {
        IdentityDatabaseUtil.closeResultSet(results);
    }

    log.debug("Association " + assocHandle + " loaded successfully from the database.");
    return assoc;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:62,代码来源:OpenIDAssociationDAO.java

示例8: getFromCache

import org.openid4java.association.Association; //导入方法依赖的package包/类
/**
 * Read entries from the cache. If no value found then returns null.
 * If the association is expired then returns null.
 * Else returns the <code>Association</code>
 *
 * @param handle
 * @return <code>Association<code>
 */
public Association getFromCache(String handle) {

    if(IdentityUtil.isBlank(handle)){
        throw new IllegalArgumentException("Handle is \'NULL\'");
    }
    OpenIDIdentityCacheKey cacheKey = new OpenIDIdentityCacheKey(0, handle);
    OpenIDIdentityCacheEntry cacheEntry = associationCache.getValueFromCache(cacheKey);
    if (cacheEntry != null) {
        if (log.isDebugEnabled()) {
            log.debug("Cache hit for handle : " + handle);
        }
        Date expiry = cacheEntry.getDate();
        String type = cacheEntry.getCacheEntry();
        Key secretKey = cacheEntry.getSecretKey();
        if(Association.TYPE_HMAC_SHA1.equals(type)){
            return Association.createHmacSha1(handle, secretKey.getEncoded(), expiry);
        } else if(Association.TYPE_HMAC_SHA256.equals(type)) {
            return Association.createHmacSha256(handle, secretKey.getEncoded(), expiry);
        } else {
            throw IdentityRuntimeException.error("Invalid algorithm " + type);
        }

        /*
         * We are not removing expired handles from the cache. If we
         * do, then at a lookup for a expired search, it will fall
         * back to a database lookup which costs a lot. JCache
         * should remove an entry if an entry was never called.
         *
         * if(association.hasExpired()){
         * associationCache.removeCacheEntry(handle);
         * if(log.isDebugEnabled()){
         * log.debug("Expired entry in cache for handle : " +
         * handle); } } else { return association; }
         */
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cache miss for handle : " + handle);
        }
        return null;
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:50,代码来源:OpenIDAssociationCache.java


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