Creates a new Message Authentication Code
@param alias algorithm to use e.g.: HmacSHA256
@return Mac implementation
436431
public Mac getMac(final @NotNull String alias) {
        try {
            Mac mac = Mac.getInstance(getAlgorithm(alias));
            mac.init(new SecretKeySpec(secret, mac.getAlgorithm()));

            return mac;
        } catch (NoSuchAlgorithmException | InvalidKeyException e) {
            throw new RuntimeException(e);
        }
    }
500729
private JMSContext createJMSContext(JMSContextInfo info, boolean tranIsActive) throws NamingException {
        inTransaction = tranIsActive;

        ConnectionFactory cf = (ConnectionFactory) new InitialContext().lookup(info.getConnectionFactoryString());

        if (inTransaction && cf instanceof XAConnectionFactory) {

            XAJMSContext xaContext = ((XAConnectionFactory) cf).createXAContext(info.getUserName(), info.getPassword());
            return xaContext.getContext();

        } else {

            return cf.createContext(info.getUserName(), info.getPassword(), info.getAcknowledgeMode());
        }
    }
493793
public synchronized byte[] mac(byte[] message) {
        ConfidentialStore cs = ConfidentialStore.get();
        if (mac == null || cs != lastCS) {
            lastCS = cs;
            mac = createMac();
        }
        return chop(mac.doFinal(message));
    }
1273121
public static ThreadFactory threadFactory(final String alias) {
    return new ThreadFactory() {
      private final ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
      private final AtomicInteger threadCount = new AtomicInteger();
      private final String poolAlias = (alias == null ? "_default_" : alias);

      @Override
      public Thread newThread(Runnable r) {
        Thread t = new Thread(threadGroup, r, "Ehcache [" + poolAlias + "]-" + threadCount.getAndIncrement());
        if(DEBUG) {
          threads.put(System.identityHashCode(t), new Exception(t.getName()));
        }
        return t;
      }
    };
  }
134702
@Override
    public boolean checkAliasAccess(Subject authenticatedSubject, String destination, String aliasDestination, int destinationType, String operationType,
                                    boolean logWarning) throws MessagingAuthorizationException {
        SibTr.entry(tc, CLASS_NAME + "checkAliasAccess", new Object[] { authenticatedSubject, aliasDestination, operationType });

        String busName = null;
        String messagingEngine = null;
        String[] roles = null;
        
        if (auditManager != null) {
            if (auditManager.getJMSBusName() != null)
                busName = auditManager.getJMSBusName();
            if (auditManager.getJMSMessagingEngine() != null)
                messagingEngine = auditManager.getJMSMessagingEngine();
        }

        roles = new String[] {MessagingSecurityConstants.OPERATION_TYPE_RECEIVE};
        if (operationType.equalsIgnoreCase(MessagingSecurityConstants.OPERATION_TYPE_BROWSE)) {
            if (checkAliasAccess(authenticatedSubject, destination, aliasDestination, destinationType, MessagingSecurityConstants.OPERATION_TYPE_RECEIVE, false)) {
                return true;
            }
        }
        String destinationName = destination + ":" + aliasDestination;

        checkIfUserIsAuthenticated(authenticatedSubject);
        String userName = null;
        String user = authenticatedSubject.getPrincipals().iterator().next().getName();
        try {
            userName = MessagingSecurityUtility.getUniqueUserName(authenticatedSubject);
        } catch (MessagingSecurityException e) {
            if (auditManager != null && auditManager.getJMSConversationMetaData() != null) {
                ConversationMetaData cmd = (ConversationMetaData) auditManager.getJMSConversationMetaData();

                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, cmd.getRemoteAddress().getHostAddress(), new Integer(cmd.getRemotePort()).toString(),
                            cmd.getChainName(), busName, messagingEngine, destinationName, operationType, roles, "aliasDestination",
                            Integer.valueOf("201"));
            } else {
                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, null, null, null, busName, messagingEngine, destinationName, operationType, 
                            roles, "aliasDestination", Integer.valueOf("201"));
            }

            throw new MessagingAuthorizationException(Tr.formatMessage(tc, "USER_NOT_AUTHORIZED_MSE1010", userName, operationType, aliasDestination), e);
        }
        Permission permission = null;
        if (destinationType == MessagingSecurityConstants.DESTINATION_TYPE_QUEUE) {
            Map<String, QueuePermission> destinationPermission = messagingSecurityService.getQueuePermissions();
            permission = destinationPermission.get(destination);
        } else if (destinationType == MessagingSecurityConstants.DESTINATION_TYPE_TOPICSPACE) {
            Map<String, TopicPermission> destinationPermission = messagingSecurityService.getTopicPermissions();
            permission = destinationPermission.get(destination);
        }
        boolean result = checkPermission(permission, operationType, userName);
        if (!result) {
            if (auditManager != null && auditManager.getJMSConversationMetaData() != null) {
                ConversationMetaData cmd = (ConversationMetaData) auditManager.getJMSConversationMetaData();

                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, cmd.getRemoteAddress().getHostAddress(), new Integer(cmd.getRemotePort()).toString(),
                            cmd.getChainName(), busName, messagingEngine, destinationName, operationType, roles, "aliasDestination",
                            Integer.valueOf("201"));
            } else {
                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, null, null, null, busName, messagingEngine, destinationName, operationType, 
                            roles, "aliasDestination", Integer.valueOf("201"));
            }
            if (logWarning) {
                SibTr.debug(tc, "USER_NOT_AUTHORIZED_MSE1010",
                            new Object[] { userName, operationType, aliasDestination });
                throw new MessagingAuthorizationException(Tr.formatMessage(tc, "USER_NOT_AUTHORIZED_MSE1010", userName, operationType, aliasDestination));               
            }

        } else {
            if (auditManager != null && auditManager.getJMSConversationMetaData() != null) {
                ConversationMetaData cmd = (ConversationMetaData) auditManager.getJMSConversationMetaData();

                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, cmd.getRemoteAddress().getHostAddress(), new Integer(cmd.getRemotePort()).toString(),
                            cmd.getChainName(), busName, messagingEngine, destinationName, operationType, roles, "aliasDestination",
                            Integer.valueOf("200"));
            } else {
                Audit.audit(Audit.EventID.SECURITY_JMS_AUTHZ_01, user, null, null, null, busName, messagingEngine, destinationName, operationType, 
                            roles, "aliasDestination", Integer.valueOf("200"));
            }

 
        }
        SibTr.exit(tc, CLASS_NAME + "checkAliasAccess", result);
        return result;
    }
331555
public static String hmacSha256(String input, String secretKey) {
        if (input == null) {
            throw new NullPointerException("input");
        } else if (secretKey == null) {
            throw new NullPointerException("secretKey");
        }
        return hmacSha256(input.getBytes(CHARSET_UTF8), secretKey.getBytes(CHARSET_UTF8));
    }
979142
public static byte[] serialize(Challenge challenge, byte[] hmacSecret) {
    MiniMessagePack.Packer packer = new MiniMessagePack.Packer();
    packer.pack(VERSION);
    packer.pack(CHALLENGE_MAGIC);
    packer.pack(challenge.getUniqueData());
    packer.pack(challenge.getValidFromTimestamp());
    packer.pack(challenge.getValidToTimestamp());
    packer.pack(challenge.getFingerprint().getBytes());
    packer.pack(challenge.getServerName());
    packer.pack(challenge.getUserName());
    byte[] bytes = packer.getBytes();
    byte[] mac = getAuthenticationCode(hmacSecret, bytes);
    packer.pack(mac);
    return packer.getBytes();
  }
521149
def get_mac_signature(api_secret, norm_request_string):
    
    hashed = hmac.new(str(api_secret), norm_request_string, hashlib.sha1)
    return binascii.b2a_base64(hashed.digest())[:-1]
1095604
public static byte[] hmacSha1(final byte[] input, final byte[] key)
		throws GeneralSecurityException {
		try {
			SecretKey secretKey = new SecretKeySpec(key, HMACSHA1_NAME);
			Mac mac = Mac.getInstance(HMACSHA1_NAME);
			mac.init(secretKey);
			return mac.doFinal(input);
		} catch (NoSuchAlgorithmException e) {
			throw new ImpossibleException(e);
		}
	}
586129
public static String makeAppSecretProof(String appSecret, String accessToken) {
		try {
			Mac mac = Mac.getInstance("HmacSHA256");
			SecretKeySpec secretKey = new SecretKeySpec(appSecret.getBytes(), "HmacSHA256");
			mac.init(secretKey);
			byte[] bytes = mac.doFinal(accessToken.getBytes());

			return Hex.encodeHexString(bytes);

		} catch (NoSuchAlgorithmException | InvalidKeyException e) {
			throw new RuntimeException(e);
		}
	}
557069
private Mac create()
        throws IOException {
        final String algo = String.format("HmacSHA%s", this.bits);
        try {
            final SecretKeySpec secret = new SecretKeySpec(
                this.key, algo
            );
            final Mac mac = Mac.getInstance(algo);
            mac.init(secret);
            return mac;
        } catch (final NoSuchAlgorithmException | InvalidKeyException ex) {
            throw new IOException(ex);
        }
    }
1308502
public static CreateResult create(String accessToken, CashCard cashCard) {
		Create<CashCard> card = new Create<CashCard>();
		card.setCard(cashCard);
		return create(accessToken, card);
	}
589976
OpenSslKeyMaterial chooseKeyMaterial(ByteBufAllocator allocator, String alias) throws Exception {
        X509Certificate[] certificates = keyManager.getCertificateChain(alias);
        if (certificates == null || certificates.length == 0) {
            return null;
        }

        PrivateKey key = keyManager.getPrivateKey(alias);
        PemEncoded encoded = PemX509Certificate.toPEM(allocator, true, certificates);
        long chainBio = 0;
        long pkeyBio = 0;
        long chain = 0;
        long pkey = 0;
        try {
            chainBio = toBIO(allocator, encoded.retain());
            chain = SSL.parseX509Chain(chainBio);

            OpenSslKeyMaterial keyMaterial;
            if (key instanceof OpenSslPrivateKey) {
                keyMaterial = ((OpenSslPrivateKey) key).newKeyMaterial(chain, certificates);
            } else {
                pkeyBio = toBIO(allocator, key);
                pkey = key == null ? 0 : SSL.parsePrivateKey(pkeyBio, password);
                keyMaterial = new DefaultOpenSslKeyMaterial(chain, pkey, certificates);
            }

            // See the chain and pkey to 0 so we will not release it as the ownership was
            // transferred to OpenSslKeyMaterial.
            chain = 0;
            pkey = 0;
            return keyMaterial;
        } finally {
            SSL.freeBIO(chainBio);
            SSL.freeBIO(pkeyBio);
            if (chain != 0) {
                SSL.freeX509Chain(chain);
            }
            if (pkey != 0) {
                SSL.freePrivateKey(pkey);
            }
            encoded.release();
        }
    }
1001252
@Function
    public static GSSContext createClientGSSContext(String server) {
        try {
            GSSManager manager = GSSManager.getInstance();
            GSSName serverName = manager.createName(server, null);

            GSSContext context = manager.createContext(serverName,
                    krb5Oid,
                    null,
                    GSSContext.DEFAULT_LIFETIME);

            context.requestMutualAuth(true);  // Mutual authentication
            context.requestConf(true);  // Will use encryption later
            context.requestInteg(true); // Will use integrity later

            return context;
        } catch (GSSException ex) {
            throw new RuntimeException("Exception creating client GSSContext", ex);
        }
    }
1210872
@Override
    public java.util.concurrent.Future<CreateAccessKeyResult> createAccessKeyAsync(
            com.amazonaws.handlers.AsyncHandler<CreateAccessKeyRequest, CreateAccessKeyResult> asyncHandler) {

        return createAccessKeyAsync(new CreateAccessKeyRequest(), asyncHandler);
    }
1142269
public static String hmacDigest(String msg, String keyString, String algo) {
		String digest = null;
		try {
			SecretKeySpec key = new SecretKeySpec(
			        (keyString).getBytes("UTF-8"), algo);
			Mac mac = Mac.getInstance(algo);
			mac.init(key);

			byte[] bytes = mac.doFinal(msg.getBytes("ASCII"));

			StringBuilder hash = new StringBuilder();
			
			for (int i = 0; i < bytes.length; i++) {
				String hex = Integer.toHexString(0xFF & bytes[i]);
				if (hex.length() == 1) {
					hash.append('0');
				}
				hash.append(hex);
			}
			digest = hash.toString();

		} catch (Exception e) {
			return null;
		}

		return digest;
	}
37382
public static ECKey signatureToKey(byte[] messageHash, String signatureBase64) throws SignatureException {
        final byte[] keyBytes = signatureToKeyBytes(messageHash, signatureBase64);
        return ECKey.fromPublicOnly(keyBytes);
    }