public OpenSSLEncryptor(OpenSSLContext context, String password) { this.context = checkNotNull(context, "context"); this.password = getUTF8Bytes(checkNotNull(password, "password")); this.prefix = getUTF8Bytes(context.getSaltPrefix()); }
@Override public String encrypt(String text) { // Null not allowed checkNotNull(text, "text"); // Convert the text into bytes byte[] bytes = getUTF8Bytes(text); // Encrypt the bytes byte[] encrypted = encrypt(bytes); // Encode as base 64 byte[] base64 = encodeBase64(encrypted); // Convert the base64 bytes into a string return getAsciiString(base64); }
private PutObjectResult writeStringToObject(String bucket, String key, String data, Optional<String> contentType) { checkNotBlank(bucket, "bucket"); checkNotBlank(key, "key"); checkNotBlank(contentType, "contentType"); checkNotNull(data, "data"); // Prevent null, but allow pure whitespace or the empty string // Convert the string into bytes using UTF8 byte[] bytes = getUTF8Bytes(data); // Setup an input stream ByteArrayInputStream in = new ByteArrayInputStream(bytes); // Setup metadata com.amazonaws.services.s3.model.ObjectMetadata meta = new com.amazonaws.services.s3.model.ObjectMetadata(); meta.setContentEncoding(UTF8); meta.setContentLength(bytes.length); if (contentType.isPresent()) { meta.setContentType(contentType.get()); } // Create a request object with the permission PublicRead PutObjectRequest request = new PutObjectRequest(bucket, key, in, meta); request.setCannedAcl(this.defaultPermissions); // Create the object return PutObjectResult.copyOf(client.putObject(request)); }