use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class SunSecurityProvider method createHash.
@Override
public byte[] createHash(InputStream data, byte[] salt, int iterations) {
if (data == null) {
throw new AssertionException("no data provided");
}
try {
MessageDigest digest = MessageDigest.getInstance(getDigestAlgorithm(), getDigestAlgorithmProvider());
digest.reset();
if (salt != null && salt.length > 0) {
digest.update(salt);
}
int n;
byte[] buf = new byte[BUF_SIZE];
while ((n = data.read(buf)) >= 0) {
digest.update(buf, 0, n);
}
byte[] key = digest.digest();
for (int i = 1; i < iterations; i++) {
key = digest.digest(key);
digest.reset();
}
return key;
} catch (NoSuchAlgorithmException | NoSuchProviderException | IOException e) {
throw new ProcessingException("Unable to hash.", e);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class SunSecurityProvider method createMac.
@Override
public byte[] createMac(byte[] password, InputStream data) {
Assertions.assertGreater(Assertions.assertNotNull(password, "no password provided").length, 0, "empty password not allowed");
if (data == null) {
throw new AssertionException("no data provided");
}
try {
String algorithm = getMacAlgorithm();
SecretKeySpec key = new SecretKeySpec(password, 0, password.length, algorithm);
Mac mac = Mac.getInstance(algorithm, getMacAlgorithmProvider());
mac.init(key);
int n;
byte[] buf = new byte[BUF_SIZE];
while ((n = data.read(buf)) >= 0) {
mac.update(buf, 0, n);
}
return mac.doFinal();
} catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException | IOException | NoSuchProviderException e) {
throw new ProcessingException("unable to create signature.", e);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class IOUtility method readString.
/**
* Reads string.
* <p>
* Stream is <em>not</em> closed. Use resource-try on streams created by caller.
*
* @param in
* @param maxLen
* max number of characters to read or -1 if the whole stream should be read.
* @return the content string
*/
public static String readString(Reader in, int maxLen) {
if (maxLen >= 0) {
try {
char[] buf = new char[maxLen];
int count = 0;
int nRead = in.read(buf, 0, maxLen);
while (nRead != -1 && count < maxLen) {
count += nRead;
nRead = in.read(buf, count, maxLen - count);
}
return new String(buf, 0, count);
} catch (IOException e) {
throw new ProcessingException("input: " + in, e);
}
} else {
try (StringWriter buffer = new StringWriter()) {
char[] b = new char[BUFFER_SIZE];
int k;
while ((k = in.read(b)) > 0) {
buffer.write(b, 0, k);
}
return buffer.toString();
} catch (IOException e) {
throw new ProcessingException("input: " + in, e);
}
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class IOUtility method createTempDirectory.
/**
* creates a temporary directory with a random name and the given suffix
*/
public static File createTempDirectory(String dirSuffix) {
try {
if (dirSuffix != null) {
dirSuffix = dirSuffix.replaceAll("[:*?\\\"<>|]*", "");
}
File tmp = File.createTempFile("dir", dirSuffix);
tmp.delete();
tmp.mkdirs();
tmp.deleteOnExit();
return tmp;
} catch (IOException e) {
throw new ProcessingException("dir: " + dirSuffix, e);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class IOUtility method writeString.
/**
* Write string.
* <p>
* Stream is <em>not</em> closed. Use resource-try on streams created by caller.
*
* @param out
* @param charset
* @param s
*/
public static void writeString(OutputStream out, String charset, String s) {
try {
OutputStreamWriter w = new OutputStreamWriter(out, charset);
w.write(s);
w.flush();
} catch (IOException e) {
throw new ProcessingException("output: " + out, e);
}
}
Aggregations