@Override public String toString() { return Base64.encodeAsString(value); } }
/** * Converts byte data to a Base64-encoded string. * * @param data * data to Base64 encode. * @return encoded Base64 string. */ public static String toBase64(byte[] data) { return Base64.encodeAsString(data); }
@Override public String encodeAsString(byte[] bytes) { return Base64.encodeAsString(bytes); } @Override public byte[] decode(String encoded) {
private String base64Encode(byte [] data) { return Base64.encodeAsString(data).replaceAll("\\s", ""); }
@Override public String convert(String val) { return Base64.encodeAsString(val.getBytes(Charset.forName("utf-8"))); } };
/** * Returns the MD5 in base64 for the data from the given input stream. * Note this method closes the given input stream upon completion. */ public static String md5AsBase64(InputStream is) throws IOException { return Base64.encodeAsString(computeMD5Hash(is)); }
/** * Returns the MD5 in base64 for the given byte array. */ public static String md5AsBase64(byte[] input) { return Base64.encodeAsString(computeMD5Hash(input)); }
/** * Returns the MD5 in base64 for the given file. */ public static String md5AsBase64(File file) throws FileNotFoundException, IOException { return Base64.encodeAsString(computeMD5Hash(file)); } }
/** * Base64 encodes the data in the specified byte buffer (from the current * position to the buffer's limit) and returns it as a base64 encoded * string. * * @param byteBuffer * The data to base64 encode and return as a string; must not be * null. * * @return The base64 encoded contents of the specified byte buffer. */ public static String fromByteBuffer(ByteBuffer byteBuffer) { return Base64.encodeAsString(copyBytesFrom(byteBuffer)); }
/** * Computes an RFC 2104-compliant HMAC signature for an array of bytes and * returns the result as a Base64 encoded string. */ protected String signAndBase64Encode(byte[] data, String key, SigningAlgorithm algorithm) throws SdkClientException { try { byte[] signature = sign(data, key.getBytes(UTF8), algorithm); return Base64.encodeAsString(signature); } catch (Exception e) { throw new SdkClientException( "Unable to calculate a request signature: " + e.getMessage(), e); } }
/** * Constructs a new customer provided server-side encryption key using the * specified raw key material. * * By default, this is assumed to be an AES-256 key, but the key algorithm * can be set through the {@link #setAlgorithm(String)} method. * * Currently, Amazon S3 only supports AES-256 encryption keys. * * @param rawKeyMaterial * The raw bytes of the customer provided encryption key. */ public SSECustomerKey(byte[] rawKeyMaterial) { if (rawKeyMaterial == null || rawKeyMaterial.length == 0) throw new IllegalArgumentException("Encryption key must be specified"); // Default to AES-256 encryption this.algorithm = SSEAlgorithm.AES256.getAlgorithm(); this.base64EncodedKey = Base64.encodeAsString(rawKeyMaterial); }
/** * Constructs a new customer provided server-side encryption key using the * specified SecretKey. * * By default, this is assumed to be an AES-256 key, but the key algorithm * can be set through the {@link #setAlgorithm(String)} method. * * Currently, Amazon S3 only supports AES-256 encryption keys. * * @param key * The customer provided server-side encryption key. */ public SSECustomerKey(SecretKey key) { if (key == null) throw new IllegalArgumentException("Encryption key must be specified"); // Default to AES-256 encryption this.algorithm = SSEAlgorithm.AES256.getAlgorithm(); this.base64EncodedKey = Base64.encodeAsString(key.getEncoded()); }
private String toJsonStringEO() { Map<String, String> map = new HashMap<String, String>(); byte[] encryptedCEK = getEncryptedCEK(); map.put(Headers.CRYPTO_KEY, Base64.encodeAsString(encryptedCEK)); byte[] iv = cipherLite.getIV(); map.put(Headers.CRYPTO_IV, Base64.encodeAsString(iv)); map.put(Headers.MATERIALS_DESCRIPTION, kekMaterialDescAsJson()); return Jackson.toJsonString(map); } /**
@Override public String toString() { StringBuilder ret = new StringBuilder(); for (Entry<String, HeaderValue> entry : headers.entrySet()) { ret.append(entry.getKey()); ret.append(": "); ret.append(entry.getValue().toString()); ret.append('\n'); } ret.append('\n'); HeaderValue contentTypeHeader = headers.get("content-type"); if (contentTypeHeader == null) { contentTypeHeader = HeaderValue.fromString("application/octet-stream"); } String contentType = contentTypeHeader.getString(); if (contentType.contains("json") || contentType.contains("text")) { ret.append(new String(payload, StringUtils.UTF8)); } else { ret.append(Base64.encodeAsString(payload)); } ret.append('\n'); return ret.toString(); } }
/** * Returns the json string in the latest format. */ private String toJsonString() { Map<String, String> map = new HashMap<String, String>(); byte[] encryptedCEK = getEncryptedCEK(); map.put(Headers.CRYPTO_KEY_V2, Base64.encodeAsString(encryptedCEK)); byte[] iv = cipherLite.getIV(); map.put(Headers.CRYPTO_IV, Base64.encodeAsString(iv)); map.put(Headers.MATERIALS_DESCRIPTION, kekMaterialDescAsJson()); // The CRYPTO_CEK_ALGORITHM, CRYPTO_TAG_LENGTH and // CRYPTO_KEYWRAP_ALGORITHM were not available in the Encryption Only // (EO) implementation ContentCryptoScheme scheme = getContentCryptoScheme(); map.put(Headers.CRYPTO_CEK_ALGORITHM, scheme.getCipherAlgorithm()); int tagLen = scheme.getTagLengthInBits(); if (tagLen > 0) map.put(Headers.CRYPTO_TAG_LENGTH, String.valueOf(tagLen)); String keyWrapAlgo = getKeyWrappingAlgorithm(); if (keyWrapAlgo != null) map.put(Headers.CRYPTO_KEYWRAP_ALGORITHM, keyWrapAlgo); return Jackson.toJsonString(map); }
/** * Adds the specified value as Base64 encoded text to the current position of the in * progress XML document. * * @param b * The binary data to add to the XML document. * * @return This XMLWriter so that additional method calls can be chained * together. */ public XMLWriter value(ByteBuffer b) { append(escapeXMLEntities(Base64.encodeAsString(BinaryUtils.copyBytesFrom(b)))); return this; }
/** * Returns the metadata in backward compatibility (old) format, so it can be * read by older version of the AWS SDK. */ private ObjectMetadata toObjectMetadataEO(ObjectMetadata metadata) { // If we generated a symmetric key to encrypt the data, store it in the // object metadata. byte[] encryptedCEK = getEncryptedCEK(); metadata.addUserMetadata(Headers.CRYPTO_KEY, Base64.encodeAsString(encryptedCEK)); // Put the cipher initialization vector (IV) into the object metadata byte[] iv = cipherLite.getIV(); metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv)); // Put the materials description into the object metadata as JSON metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, kekMaterialDescAsJson()); return metadata; }
/** * Initializes multipart upload. */ private void initMultiPartUpload() throws IOException { // Generate the object metadata by setting server side encryption, md5 checksum, // and encoding as octet stream since no assumptions are made about the file type ObjectMetadata meta = new ObjectMetadata(); if (mSseEnabled) { meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } if (mHash != null) { meta.setContentMD5(Base64.encodeAsString(mHash.digest())); } meta.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM); AmazonClientException lastException; InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(mBucketName, mKey).withObjectMetadata(meta); do { try { mUploadId = mClient.initiateMultipartUpload(initRequest).getUploadId(); return; } catch (AmazonClientException e) { lastException = e; } } while (mRetryPolicy.attempt()); // This point is only reached if the operation failed more // than the allowed retry count throw new IOException("Unable to init multipart upload to " + mKey, lastException); }
ImportKeyPairRequest importKeyPairRequest = (ImportKeyPairRequest)originalRequest; String publicKeyMaterial = importKeyPairRequest.getPublicKeyMaterial(); String encodedKeyMaterial = Base64.encodeAsString(publicKeyMaterial.getBytes()); request.addParameter("PublicKeyMaterial", encodedKeyMaterial);
Base64.encodeAsString(encryptedCEK)); metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv));