生成sign HMAC-SHA256 或 MD5 签名
@param map map
@param paternerKey paternerKey
@return sign
178076
public static String generateSign(Map<String, String> map,String paternerKey){
		return generateSign(map, null, paternerKey);
	}
1116743
public static String genPaySignMD5(Map<String, Object> map, String key) {
        return genPaySign(map, key, "MD5");
    }
664951
public static String hmacMd5(String data, String key) {
        return hmacMd5(data.getBytes(), key.getBytes());
    }
755051
public static function signWithPKCS15(RSAKey $key, string $message, string $hash): string
    {
        $em = self::encodeEMSA15($message, $key->getModulusLength(), Hash::$hash());
        $message = BigInteger::createFromBinaryString($em);
        $signature = RSAKey::exponentiate($key, $message);

        return self::convertIntegerToOctetString($signature, $key->getModulusLength());
    }
1090303
def sign(self, h):
        
        if not self.is_private():
            raise RuntimeError("Key must be private to be able to sign")
        val = from_bytes_32(h)
        r, s = self._generator.sign(self.secret_exponent(), val)
        return sigencode_der(r, s)
1202204
private static String generateSignByRule(TreeMap<String, String> map) {
    String sign = "";
    Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry<String, String> entry = it.next();
      if (it.hasNext()) {
        if (entry.getValue() != null && !"".equals(entry.getValue().toString().trim())) {
          sign += entry.getKey() + "=" + entry.getValue() + "&";
        }
      } else {
        if (entry.getValue() != null && !"".equals(entry.getValue().toString().trim())) {
          sign += entry.getKey() + "=" + entry.getValue();
        } else {
          sign = sign.substring(0, sign.length() - 1);
        }
      }
    }
    return getMD5(sign);
  }
151433
public String sign(KeyStoreChooser keyStoreChooser, PrivateKeyChooserByAlias privateKeyChooserByAlias, String message) {
		Base64EncodedSigner signer = cache.get(cacheKey(keyStoreChooser, privateKeyChooserByAlias));

		if (signer != null) {
			return signer.sign(message);
		}

		Base64EncodedSignerImpl signerImpl = new Base64EncodedSignerImpl();
		signerImpl.setAlgorithm(algorithm);
		signerImpl.setCharsetName(charsetName);
		signerImpl.setProvider(provider);
		PrivateKey privateKey = privateKeyRegistryByAlias.get(keyStoreChooser, privateKeyChooserByAlias);

		if (privateKey == null) {
			throw new SignatureException("private key not found: keyStoreName=" + keyStoreChooser.getKeyStoreName()
					+ ", alias=" + privateKeyChooserByAlias.getAlias());
		}

		signerImpl.setPrivateKey(privateKey);
		cache.put(cacheKey(keyStoreChooser, privateKeyChooserByAlias), signerImpl);
		return signerImpl.sign(message);
	}
385703
public String sign(String privateKeyId, String message) {
		Base64EncodedSigner signer = cache.get(privateKeyId);

		if (signer != null) {
			return signer.sign(message);
		}

		Base64EncodedSignerImpl signerImpl = new Base64EncodedSignerImpl();
		signerImpl.setAlgorithm(algorithm);
		signerImpl.setCharsetName(charsetName);
		signerImpl.setProvider(provider);
		PrivateKey privateKey = privateKeyMap.get(privateKeyId);

		if (privateKey == null) {
			throw new SignatureException("private key not found: privateKeyId=" + privateKeyId);
		}

		signerImpl.setPrivateKey(privateKey);
		cache.put(privateKeyId, signerImpl);
		return signerImpl.sign(message);
	}
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));
    }
324316
public static String createSign(Map<String, String> packageParams, String signKey) {
        SortedMap<String, String> sortedMap = new TreeMap<String, String>();
        sortedMap.putAll(packageParams);

        List<String> keys = new ArrayList<String>(packageParams.keySet());
        Collections.sort(keys);


        StringBuffer toSign = new StringBuffer();
        for (String key : keys) {
            String value = packageParams.get(key);
            if (null != value && !"".equals(value) && !"sign".equals(key)
                    && !"key".equals(key)) {
                toSign.append(key + "=" + value + "&");
            }
        }
        toSign.append("key=" + signKey);
        String sign = DigestUtils.md5Hex(toSign.toString())
                .toUpperCase();
        return sign;
    }
846583
protected static final byte[] signISO9796(byte[][] key, byte[] data, int off, int len) throws Exception {
        CachingKey ck = new CachingKey(key, data, off, len);
        CachingKey result = cryptoKeysMap.get(ck);

        if (result != null) {
            result.successfulUses += 1;
            result.reused = true;
            return result.result;
        } else {
            if (cryptoKeysMap.size() > MAX_CACHE) {
                try {
                    CachingKey[] keys = cryptoKeysMap.keySet().toArray(new CachingKey[cryptoKeysMap.size()]);
                    Arrays.sort(keys, cachingKeyComparator);
                    if (cachingKeyComparator.compare(keys[0], keys[keys.length - 1]) < 0) {
                        for (int i = 0; i < cryptoKeysMap.size() / 5; i++) {
                            cryptoKeysMap.remove(keys[i]);
                            keys[i + 1 * cryptoKeysMap.size() / 5].successfulUses--;
                            keys[i + 2 * cryptoKeysMap.size() / 5].successfulUses--;
                            keys[i + 3 * cryptoKeysMap.size() / 5].successfulUses--;
                            keys[i + 4 * cryptoKeysMap.size() / 5].successfulUses--;
                        }
                    } else {
                        for (int i = 0; i < cryptoKeysMap.size() / 5; i++) {
                            cryptoKeysMap.remove(keys[keys.length - 1 - i]);
                            keys[keys.length - 1 - i - 1 * cryptoKeysMap.size() / 5].successfulUses--;
                            keys[keys.length - 1 - i - 2 * cryptoKeysMap.size() / 5].successfulUses--;
                            keys[keys.length - 1 - i - 3 * cryptoKeysMap.size() / 5].successfulUses--;
                            keys[keys.length - 1 - i - 4 * cryptoKeysMap.size() / 5].successfulUses--;
                        }
                    }
                } catch (Exception e) {
                    // do nothing. since this code is used for the command line utility, no log is taken.
                }
                 
            }
        }

        /** Invoked by LTPADigSignature **/
        BigInteger n = new BigInteger(key[0]);
        BigInteger e = new BigInteger(key[2]);
        BigInteger p = new BigInteger(key[3]);
        BigInteger q = new BigInteger(key[4]);
        BigInteger d = e.modInverse((p.subtract(BigInteger.ONE)).multiply(q.subtract(BigInteger.ONE)));
        KeyFactory kFact = null;
        if (LTPAKeyUtil.isIBMJCEAvailable()) {
            kFact = KeyFactory.getInstance(CRYPTO_ALGORITHM, IBMJCE_NAME);
        } else {
            kFact = KeyFactory.getInstance(CRYPTO_ALGORITHM);
        }


        BigInteger pep = new BigInteger(key[5]);
        BigInteger peq = new BigInteger(key[6]);
        BigInteger crtC = new BigInteger(key[7]);
        RSAPrivateCrtKeySpec privCrtKeySpec = new RSAPrivateCrtKeySpec(n, e, d, p, q, pep, peq, crtC);
        PrivateKey privKey = kFact.generatePrivate(privCrtKeySpec);

        Signature rsaSig = null;
        if (LTPAKeyUtil.isIBMJCEAvailable()) {
            rsaSig = Signature.getInstance(SIGNATURE_ALGORITHM, IBMJCE_NAME);
        } else {
            rsaSig = Signature.getInstance(SIGNATURE_ALGORITHM);
        }
        rsaSig.initSign(privKey);
        rsaSig.update(data, off, len);
        byte[] sig = rsaSig.sign();

        cryptoKeysMap.put(ck, ck);
        ck.result = sig;
        ck.successfulUses = 0;

        return sig;
    }
900164
def key_sign(rsakey, message, digest):
    """"""
    padding = _asymmetric.padding.PKCS1v15()
    signature = rsakey.sign(message, padding, digest)
    return signature
612548
public static String hmac(String string) throws NoSuchAlgorithmException, InvalidKeyException {
        String code = "";
        KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacMD5");
        SecretKey secretKey = keyGenerator.generateKey();
        SecretKey secretKey2 = new SecretKeySpec(secretKey.getEncoded(), "HmacMD5");
        Mac mac = Mac.getInstance(secretKey.getAlgorithm());
        mac.init(secretKey2);
        return code;
    }
27189
@Override
    public Builder signWith(String algorithm, Key key) throws KeyException {

        if (algorithm == null || algorithm.isEmpty() || !algorithm.equals(Constants.SIGNATURE_ALG_RS256)) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_ALGORITHM_ERR", new Object[] { algorithm, Constants.SIGNATURE_ALG_RS256 });
            throw new KeyException(err);
        }
        if (key == null || !(key instanceof RSAPrivateKey)) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_KEY_ERR", new Object[] { algorithm, key });
            throw new KeyException(err);
        }
        alg = algorithm;
        privateKey = key;
        return this;
    }
778696
public static String hmacSHA1(String data, String key) {
        return hmacSHA1(data.getBytes(), key.getBytes());
    }
1160119
public static String sha1hmac(String key, String plaintext, int encoding)
	{
		byte[] signature = sha1hmac(key.getBytes(), plaintext.getBytes());

		return encode(signature, encoding);
	}
1267531
protected String hash(String key) throws VictimsException {
        try {
            MessageDigest mda = MessageDigest
                    .getInstance(MessageDigestAlgorithms.SHA_256);
            return Hex.encodeHexString(mda.digest(key.getBytes()));
        } catch (NoSuchAlgorithmException e) {
            throw new VictimsException(String.format("Could not hash key: %s",
                    key), e);
        }
    }