use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class TableUserFilterManager method setSerializedData.
/**
* Import the serialized data, e.g. after restoring from a bookmark
*/
public void setSerializedData(byte[] data) {
try {
reset();
Collection<IUserFilterState> filterStates = SerializationUtility.createObjectSerializer().deserialize(data, null);
for (IUserFilterState filterState : filterStates) {
boolean success = filterState.notifyDeserialized(m_table);
if (success) {
addFilter(filterState);
} else {
LOG.info("User filter state of table '{}' cannot be deserialized because the column could not be found. Ignoring element.", m_table.getClass().getName());
}
}
} catch (IOException | ClassNotFoundException e) {
throw new ProcessingException("Failed reading user filter data.", e);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class SunSecurityProvider method verifySignature.
@Override
public boolean verifySignature(byte[] publicKey, InputStream data, byte[] signatureToVerify) {
Assertions.assertGreater(Assertions.assertNotNull(publicKey, "no public key provided").length, 0, "empty public key not allowed");
Assertions.assertGreater(Assertions.assertNotNull(signatureToVerify, "no signature provided").length, 0, "empty signature not allowed");
if (data == null) {
throw new AssertionException("no data provided");
}
try {
// create public key from bytes
KeyFactory keyFactory = KeyFactory.getInstance(getKeyPairGenerationAlgorithm(), getSignatureProvider());
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(publicKey);
PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);
// verify signature
Signature sig = Signature.getInstance(getSignatureAlgorithm(), getSignatureProvider());
sig.initVerify(pubKey);
int n;
byte[] buf = new byte[BUF_SIZE];
while ((n = data.read(buf)) >= 0) {
sig.update(buf, 0, n);
}
return sig.verify(signatureToVerify);
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException | InvalidKeyException | SignatureException | IOException t) {
throw new ProcessingException("unable to verify signature", t);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class SunSecurityProvider method createKeyPair.
@Override
public KeyPairBytes createKeyPair() {
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(getKeyPairGenerationAlgorithm(), getSignatureProvider());
ECGenParameterSpec spec = new ECGenParameterSpec(getEllipticCurveName());
keyGen.initialize(spec, createSecureRandom());
KeyPair keyPair = keyGen.generateKeyPair();
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(keyPair.getPublic().getEncoded());
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded());
return new KeyPairBytes(pkcs8EncodedKeySpec.getEncoded(), x509EncodedKeySpec.getEncoded());
} catch (NoSuchProviderException | InvalidAlgorithmParameterException | NoSuchAlgorithmException e) {
throw new ProcessingException("unable to create a new key-pair", e);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class SunSecurityProvider method doCrypt.
protected void doCrypt(InputStream input, OutputStream output, EncryptionKey key, int mode) {
Assertions.assertNotNull(key, "key must not be null.");
if (input == null) {
throw new AssertionException("input must not be null.");
}
if (output == null) {
throw new AssertionException("output must not be null.");
}
try {
Cipher cipher = Cipher.getInstance(getCipherAlgorithm() + "/" + getCipherAlgorithmMode() + "/" + getCipherAlgorithmPadding(), getCipherAlgorithmProvider());
cipher.init(mode, key.get(), key.params());
try (OutputStream out = new CipherOutputStream(output, cipher)) {
int n;
byte[] buf = new byte[BUF_SIZE];
while ((n = input.read(buf)) >= 0) {
out.write(buf, 0, n);
}
}
} catch (NoSuchAlgorithmException e) {
throw new ProcessingException("Unable to crypt data. Algorithm could not be found. Make sure to use JRE 1.8 or newer.", e);
} catch (NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | NoSuchProviderException | IOException e) {
throw new ProcessingException("Unable to crypt data.", e);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class SunSecurityProvider method createEncryptionKey.
@Override
public EncryptionKey createEncryptionKey(char[] password, byte[] salt, int keyLen) {
Assertions.assertGreater(Assertions.assertNotNull(password, "password must not be null.").length, 0, "empty password is not allowed.");
Assertions.assertGreater(Assertions.assertNotNull(salt, "salt must be provided.").length, 0, "empty salt is not allowed.");
Assertions.assertTrue(keyLen == 128 || keyLen == 192 || keyLen == 256, "key length must be 128, 192 or 256.");
try {
SecretKeyFactory factory = SecretKeyFactory.getInstance(getSecretKeyAlgorithm(), getCipherAlgorithmProvider());
KeySpec spec = new PBEKeySpec(password, salt, getKeyDerivationIterationCount(), keyLen + (GCM_INITIALIZATION_VECTOR_LEN * 8));
SecretKey tmpSecret = factory.generateSecret(spec);
// derive Key and Initialization Vector
byte[] encoded = tmpSecret.getEncoded();
byte[] iv = new byte[GCM_INITIALIZATION_VECTOR_LEN];
byte[] key = new byte[keyLen / 8];
System.arraycopy(encoded, 0, key, 0, key.length);
System.arraycopy(encoded, key.length, iv, 0, GCM_INITIALIZATION_VECTOR_LEN);
SecretKey secretKey = new SecretKeySpec(key, getCipherAlgorithm());
GCMParameterSpec parameters = new GCMParameterSpec(GCM_AUTH_TAG_BIT_LEN, iv);
return new EncryptionKey(secretKey, parameters);
} catch (NoSuchAlgorithmException e) {
throw new ProcessingException("Unable to create secret. Algorithm could not be found. Make sure to use JRE 1.8 or newer.", e);
} catch (InvalidKeySpecException | NoSuchProviderException e) {
throw new ProcessingException("Unable to create secret.", e);
}
}
Aggregations