protected String getPrivateKey(com.jcraft.jsch.KeyPair keyPair) { ByteArrayOutputStream out = new ByteArrayOutputStream(); keyPair.writePrivateKey(out); return getUTF8String(out.toByteArray()); }
protected String getPublicKey(com.jcraft.jsch.KeyPair keyPair, String name) { ByteArrayOutputStream out = new ByteArrayOutputStream(); keyPair.writePublicKey(out, name); return getUTF8String(out.toByteArray()); }
@Override public String readObjectToString(String bucket, String key) { checkNotBlank(bucket, "bucket"); checkNotBlank(key, "key"); ByteArrayOutputStream out = new ByteArrayOutputStream(); copyObjectToStream(bucket, key, out); return getUTF8String(out.toByteArray()); }
@Override public String decrypt(String text) { // Null not allowed checkNotNull(text, "text"); // Decode the base64 text into bytes byte[] bytes = decodeBase64(getAsciiBytes(checkBase64(text))); // OpenSSL inserts the prefix "Salted__" followed by the salt itself int saltOffset = context.getSaltPrefix().length(); byte[] salt = copyOfRange(bytes, saltOffset, saltOffset + context.getSaltSize()); // encrypted bytes come after the prefix and the salt int encryptedBytesOffset = saltOffset + context.getSaltSize(); // extract the portion of the array containing the encrypted bytes byte[] encrypted = copyOfRange(bytes, encryptedBytesOffset, bytes.length); // decrypt the bytes using the salt that was embedded in the text byte[] decrypted = doCipher(context, DECRYPT_MODE, salt, encrypted, password); // Construct a string from the decrypted bytes return getUTF8String(decrypted); }