} else {
download = new File(storagePath, name);
}
if (this.publicKey != null && signatureBytes != null) {
// copy to file and check signature
SignatureOutputStream verifyOutput = null;
try {
verifyOutput = new SignatureOutputStream(new FileOutputStream(download), CryptoLib.signAlgorithm, this.publicKey);
client.writeTo(new BufferedOutputStream(verifyOutput));
if (!verifyOutput.verify(signatureBytes)) throw new IOException("Bad Signature!");
} catch (final NoSuchAlgorithmException e) {
throw new IOException("No such algorithm");
} catch (final SignatureException e) {
throw new IOException("Signature exception");
} finally {
if (verifyOutput != null)
verifyOutput.close();
}
// Save signature
final File signatureFile = new File(download.getAbsoluteFile() + ".sig");
FileUtils.copy(UTF8.getBytes(Base64Order.standardCoder.encode(signatureBytes)), signatureFile);
if ((!signatureFile.exists()) || (signatureFile.length() == 0)) throw new IOException("create signature file failed");