private static String hmacToString(String methodName, Key key) { return String.format( "Hashing.%s(Key[algorithm=%s, format=%s])", methodName, key.getAlgorithm(), key.getFormat()); }
@Override protected boolean isMyType(Key key) { return "EdDSA".equals(key.getAlgorithm()); } },
/** * Returns true if the key is an elliptic curve public or private key. */ public static boolean isEcKey(Key key) { return "EC".equals(key.getAlgorithm()); }
/** * Returns true if the key is an RSA public or private key. */ public static boolean isRsaKey(Key key) { return "RSA".equals(key.getAlgorithm()); }
private static String hmacToString(String methodName, Key key) { return String.format( "Hashing.%s(Key[algorithm=%s, format=%s])", methodName, key.getAlgorithm(), key.getFormat()); }
private static String hmacToString(String methodName, Key key) { return String.format( "Hashing.%s(Key[algorithm=%s, format=%s])", methodName, key.getAlgorithm(), key.getFormat()); }
private String getSignatureAlgorithm() throws Exception { InputStream is = null; try { is = new BufferedInputStream(new FileInputStream(config.mSignatureFile)); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(is, config.mStorePass.toCharArray()); Key key = keyStore.getKey(config.mStoreAlias, config.mKeyPass.toCharArray()); String keyAlgorithm = key.getAlgorithm(); String signatureAlgorithm; if (keyAlgorithm.equalsIgnoreCase("DSA")) { signatureAlgorithm = "SHA1withDSA"; } else if (keyAlgorithm.equalsIgnoreCase("RSA")) { signatureAlgorithm = "SHA1withRSA"; } else if (keyAlgorithm.equalsIgnoreCase("EC")) { signatureAlgorithm = "SHA1withECDSA"; } else { throw new RuntimeException("private key is not a DSA or " + "RSA key"); } return signatureAlgorithm; } finally { StreamUtil.closeQuietly(is); } }
public Key engineGetKey(final String alias, final char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException { try { final Key key = delegate.getKey(alias, password); return key instanceof SecretKey && "password".equals(key.getAlgorithm()) ? decoded((SecretKey) key) : key; } catch (KeyStoreException e) { throw new IllegalStateException(e); } }
private static String hmacToString(String methodName, Key key) { return String.format( "Hashing.%s(Key[algorithm=%s, format=%s])", methodName, key.getAlgorithm(), key.getFormat()); }
boolean isEqual(Key key) { return Objects.equals(key.getAlgorithm(), algorithm) && Objects.equals(key.getFormat(), format); } }
static boolean isECKeyWithFieldSize(Key key, int fieldSize) { return "ECDSA".equals(key.getAlgorithm()) && fieldSizeFromKey((ECKey) key) == fieldSize; }
/** * @param kek * the key encrypting key, which is either an AES key or a public * key */ String getKeyWrapAlgorithm(Key kek) { String algorithm = kek.getAlgorithm(); if (S3CryptoScheme.AES.equals(algorithm)) { return AESWrap; } if (S3CryptoScheme.RSA.equals(algorithm)) { if (CryptoRuntime.isRsaKeyWrapAvailable()) return RSA_ECB_OAEPWithSHA256AndMGF1Padding; } return null; }
RawKey(Key original) { algorithm = original.getAlgorithm(); format = original.getFormat(); final byte[] encoded = original.getEncoded(); this.encoded = encoded == null ? null : encoded.clone(); }
/** * @param key Cipher Key. * @param encMode Enc mode see {@link Cipher#ENCRYPT_MODE}, {@link Cipher#DECRYPT_MODE}, etc. */ public static Cipher createCipher(Key key, int encMode) { if (key == null) throw new IgniteException("Cipher Key cannot be null"); try { Cipher cipher = Cipher.getInstance(key.getAlgorithm()); cipher.init(encMode, key); return cipher; } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) { throw new IgniteException(e); } }
@Signature public String getAlgorithm() { return getWrappedObject().getAlgorithm(); } }
@Test public void loadSecretKeyFromFile_trim_content() throws Exception { URL resource = getClass().getResource("/org/sonar/api/config/AesCipherTest/non_trimmed_secret_key.txt"); String path = new File(resource.toURI()).getCanonicalPath(); AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(path); assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); assertThat(secretKey.getEncoded().length).isGreaterThan(10); }
@Test public void loadSecretKeyFromFile() throws Exception { AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey()); assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); assertThat(secretKey.getEncoded().length).isGreaterThan(10); }
@Test public void loadSecretKeyFromFile_trim_content() throws Exception { String path = getPath("non_trimmed_secret_key.txt"); AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(path); assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); assertThat(secretKey.getEncoded().length).isGreaterThan(10); }
@Test public void loadSecretKeyFromFile() throws Exception { AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey()); assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); assertThat(secretKey.getEncoded().length).isGreaterThan(10); }
@Test public void testTestProvider() { Configuration conf = HBaseConfiguration.create(); conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName()); KeyProvider provider = Encryption.getKeyProvider(conf); assertNotNull("Null returned for provider", provider); assertTrue("Provider is not the expected type", provider instanceof KeyProviderForTesting); Key key = provider.getKey("foo"); assertNotNull("Test provider did not return a key as expected", key); assertEquals("Test provider did not create a key for AES", "AES", key.getAlgorithm()); assertEquals("Test provider did not create a key of adequate length", AES.KEY_LENGTH, key.getEncoded().length); }