@Override public byte[] applyPrivateKeyCipher(byte[] bytes, PrivateKeyEncryptionContext encContext, boolean encryptIt) throws GeneralSecurityException { int keyLength = resolveKeyLength(encContext); byte[] keyValue = deriveEncryptionKey(encContext, keyLength / Byte.SIZE); return applyPrivateKeyCipher(bytes, encContext, keyLength, keyValue, encryptIt); }
@Override public List<Integer> getSupportedKeySizes() { return getAvailableKeyLengths(); }
@Override protected int resolveKeyLength(PrivateKeyEncryptionContext encContext) throws GeneralSecurityException { String cipherType = encContext.getCipherType(); try { int keyLength = Integer.parseInt(cipherType); List<Integer> sizes = getSupportedKeySizes(); for (Integer s : sizes) { if (s.intValue() == keyLength) { return keyLength; } } throw new InvalidKeySpecException("Unknown " + getCipherName() + " key length: " + cipherType + " - supported: " + sizes); } catch (NumberFormatException e) { throw new InvalidKeySpecException("Bad " + getCipherName() + " key length (" + cipherType + "): " + e.getMessage(), e); } }
@Override protected int resolveKeyLength(PrivateKeyEncryptionContext encContext) throws GeneralSecurityException { String cipherType = encContext.getCipherType(); try { int keyLength = Integer.parseInt(cipherType); List<Integer> sizes = getSupportedKeySizes(); for (Integer s : sizes) { if (s.intValue() == keyLength) { return keyLength; } } throw new InvalidKeySpecException("Unknown " + getCipherName() + " key length: " + cipherType + " - supported: " + sizes); } catch (NumberFormatException e) { throw new InvalidKeySpecException("Bad " + getCipherName() + " key length (" + cipherType + "): " + e.getMessage(), e); } }
@Override public byte[] applyPrivateKeyCipher( byte[] bytes, PrivateKeyEncryptionContext encContext, boolean encryptIt) throws GeneralSecurityException, IOException { int keyLength = resolveKeyLength(encContext); byte[] keyValue = deriveEncryptionKey(encContext, keyLength / Byte.SIZE); return applyPrivateKeyCipher(bytes, encContext, keyLength, keyValue, encryptIt); }
@Override public List<Integer> getSupportedKeySizes() { return getAvailableKeyLengths(); }