/** {@inheritDoc} */ @Override public String convert(@Nonnull final String source) { return "{sha1}" + CodecUtil.hex(HashUtil.sha1(source.getBytes())); } }
@Override public String apply(@Nonnull final String input) { return CodecUtil.hex(HashUtil.sha1(input.getBytes())); }
/** {@inheritDoc} */ @Override public String convert(@Nonnull final String source) { return "{md5}" + CodecUtil.hex(HashUtil.hash(new MD5Digest(), source.getBytes())); } }
@Override protected byte[] decryptKey(final byte[] encrypted, final char[] password) { final String pem = new String(encrypted, ByteUtil.ASCII_CHARSET); final int start = pem.indexOf(PemUtil.DEK_INFO); final int eol = pem.indexOf('\n', start); final String[] dekInfo = pem.substring(start + 10, eol).split(","); final String alg = dekInfo[0]; final byte[] iv = CodecUtil.hex(dekInfo[1]); final byte[] bytes = PemUtil.decode(encrypted); return new OpenSSLEncryptionScheme(OpenSSLAlgorithm.fromAlgorithmId(alg), iv, password).decrypt(bytes); }
/** * Creates a memcached key from one or more parts. * * @param parts Key parts (i.e. namespace, local name) * * @return Key comprised of 250 characters or less. */ private String memcachedKey(final String ... parts) { final String key; if (parts.length > 0) { final StringBuilder sb = new StringBuilder(); int i = 0; for (String part : parts) { if (i++ > 0) { sb.append(':'); } sb.append(part); } key = sb.toString(); } else { key = parts[0]; } if (key.length() > MAX_KEY_LENGTH) { return CodecUtil.hex(HashUtil.sha512(key)); } return key; }
/** * Gets the subject key identifier of the given certificate in delimited hexadecimal format, e.g. <code> * 25:48:2f:28:ec:5d:19:bb:1d:25:ae:94:93:b1:7b:b5:35:96:24:66</code>. * * @param cert Certificate to process. * * @return Subject key identifier in colon-delimited hex format. * * @throws EncodingException on cert field extraction. */ public static String subjectKeyId(final X509Certificate cert) throws EncodingException { return CodecUtil.hex(new ExtensionReader(cert).readSubjectKeyIdentifier().getKeyIdentifier(), true); }
/** * Gets the authority key identifier of the given certificate in delimited hexadecimal format, e.g. <code> * 25:48:2f:28:ec:5d:19:bb:1d:25:ae:94:93:b1:7b:b5:35:96:24:66</code>. * * @param cert Certificate to process. * * @return Authority key identifier in colon-delimited hex format. * * @throws EncodingException on cert field extraction. */ public static String authorityKeyId(final X509Certificate cert) throws EncodingException { return CodecUtil.hex(new ExtensionReader(cert).readAuthorityKeyIdentifier().getKeyIdentifier(), true); } }
/** * Creates a cache-wide unique namespace for the given context name. The context-namespace mapping is stored * in the cache. * * @param context Context name. * * @return Namespace name for given context. * * @throws java.io.IOException On memcached operation errors. */ protected String createNamespace(final String context) throws IOException { String namespace = null; boolean success = false; // Perform successive add operations until success to ensure unique namespace while (!success) { namespace = CodecUtil.hex(ByteUtil.toBytes(System.currentTimeMillis())); // Namespace values are safe for memcached keys success = handleAsyncResult(memcacheClient.add(namespace, 0, context, stringTranscoder)); } // Create the reverse mapping to support looking up namespace by context name if (!handleAsyncResult(memcacheClient.add(memcachedKey(context), 0, namespace, stringTranscoder))) { throw new IllegalStateException(context + " already exists"); } return namespace; }