diff --git a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/options/CreateServerOptions.java b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/options/CreateServerOptions.java index 6120f80682..a23094b93f 100644 --- a/apis/cloudservers/src/main/java/org/jclouds/cloudservers/options/CreateServerOptions.java +++ b/apis/cloudservers/src/main/java/org/jclouds/cloudservers/options/CreateServerOptions.java @@ -29,7 +29,7 @@ import java.util.Map.Entry; import javax.inject.Inject; import org.jclouds.cloudservers.domain.Addresses; -import org.jclouds.encryption.internal.Base64; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.http.HttpRequest; import org.jclouds.rest.MapBinder; import org.jclouds.rest.binders.BindToJsonPayload; @@ -54,7 +54,7 @@ public class CreateServerOptions implements MapBinder { public File(String path, byte[] contents) { this.path = checkNotNull(path, "path"); - this.contents = Base64.encodeBytes(checkNotNull(contents, "contents")); + this.contents = CryptoStreams.base64(checkNotNull(contents, "contents")); checkArgument(path.getBytes().length < 255, String.format( "maximum length of path is 255 bytes. Path specified %s is %d bytes", path, path.getBytes().length)); checkArgument(contents.length < 10 * 1024, String.format( diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedData.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedData.java index 90c64fa08a..5ae41b6cf8 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedData.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedData.java @@ -8,9 +8,9 @@ import javax.crypto.Cipher; import org.jclouds.cloudstack.domain.EncryptedPasswordAndPrivateKey; import org.jclouds.crypto.Crypto; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.crypto.Pems; import org.jclouds.domain.LoginCredentials; -import org.jclouds.encryption.internal.Base64; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Charsets; @@ -46,7 +46,7 @@ public class WindowsLoginCredentialsFromEncryptedData implements Function 0, "userData cannot be empty"); checkArgument(length <= 2 * 1024, "userData cannot be larger than 2kb"); - this.queryParameters.replaceValues("userdata", ImmutableSet.of(Base64.encodeBytes(unencodedData))); + this.queryParameters.replaceValues("userdata", ImmutableSet.of(CryptoStreams.base64(unencodedData))); return this; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/WindowsLoginCredentialsFromEncryptedData.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/WindowsLoginCredentialsFromEncryptedData.java index 9a8d908edc..dbbd1eb0f5 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/WindowsLoginCredentialsFromEncryptedData.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/WindowsLoginCredentialsFromEncryptedData.java @@ -26,10 +26,10 @@ import javax.crypto.Cipher; import javax.inject.Inject; import org.jclouds.crypto.Crypto; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.crypto.Pems; import org.jclouds.domain.LoginCredentials; import org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey; -import org.jclouds.encryption.internal.Base64; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Charsets; @@ -64,7 +64,7 @@ public class WindowsLoginCredentialsFromEncryptedData implements Function @@ -89,7 +90,7 @@ public class RunInstancesOptions extends BaseEC2RequestOptions { int length = checkNotNull(unencodedData, "unencodedData").length; checkArgument(length > 0, "userData cannot be empty"); checkArgument(length <= 16 * 1024, "userData cannot be larger than 16kb"); - formParameters.put("UserData", Base64.encodeBytes(unencodedData)); + formParameters.put("UserData", CryptoStreams.base64(unencodedData)); return this; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/GetConsoleOutputResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/GetConsoleOutputResponseHandler.java index 631798d448..445b9c39a4 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/GetConsoleOutputResponseHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/GetConsoleOutputResponseHandler.java @@ -18,7 +18,7 @@ */ package org.jclouds.ec2.xml; -import org.jclouds.encryption.internal.Base64; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.http.functions.ParseSax; import com.google.common.base.Charsets; @@ -41,7 +41,7 @@ public class GetConsoleOutputResponseHandler extends ParseSax.HandlerWithResult< @Override public void endElement(String uri, String name, String qName) { if (qName.equalsIgnoreCase("output")) { - this.output = new String(Base64.decode(currentText.toString().trim()), Charsets.UTF_8); + this.output = new String(CryptoStreams.base64(currentText.toString().trim()), Charsets.UTF_8); } currentText = new StringBuilder(); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index c81e0fedee..0c26af735c 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/strategy/CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -36,6 +36,7 @@ import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.domain.LoginCredentials; import org.jclouds.ec2.compute.domain.EC2HardwareBuilder; import org.jclouds.ec2.compute.domain.RegionAndName; @@ -44,7 +45,6 @@ import org.jclouds.ec2.compute.options.EC2TemplateOptions; import org.jclouds.ec2.domain.BlockDeviceMapping; import org.jclouds.ec2.domain.KeyPair; import org.jclouds.ec2.options.RunInstancesOptions; -import org.jclouds.encryption.internal.Base64; import org.jclouds.scriptbuilder.domain.Statements; import org.testng.annotations.Test; @@ -200,7 +200,7 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest { assertEquals( customize.buildFormParameters().entries(), ImmutableMultimap. of("InstanceType", size.getProviderId(), "SecurityGroup.1", "group", - "KeyName", systemGeneratedKeyPairName, "UserData", Base64.encodeBytes("hello".getBytes())).entries()); + "KeyName", systemGeneratedKeyPairName, "UserData", CryptoStreams.base64("hello".getBytes())).entries()); assertEquals(customize.buildMatrixParameters(), ImmutableMultimap. of()); assertEquals(customize.buildRequestHeaders(), ImmutableMultimap. of()); assertEquals(customize.buildStringPayload(), null); diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java index 9ad40caf6e..e9e30558dc 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/options/CreateServerOptions.java @@ -25,13 +25,13 @@ import static com.google.common.base.Preconditions.checkState; import java.beans.ConstructorProperties; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import javax.inject.Inject; import javax.inject.Named; -import org.jclouds.encryption.internal.Base64; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.http.HttpRequest; import org.jclouds.openstack.nova.domain.SecurityGroup; import org.jclouds.rest.MapBinder; @@ -55,7 +55,7 @@ public class CreateServerOptions implements MapBinder { public File(String path, byte[] contents) { this.path = checkNotNull(path, "path"); - this.contents = Base64.encodeBytes(checkNotNull(contents, "contents")); + this.contents = CryptoStreams.base64(checkNotNull(contents, "contents")); checkArgument(path.getBytes().length < 255, String.format( "maximum length of path is 255 bytes. Path specified %s is %d bytes", path, path.getBytes().length)); checkArgument(contents.length < 10 * 1024, String.format( diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java index 7fa405b903..db02545d1c 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java @@ -32,14 +32,16 @@ import java.util.Set; import javax.inject.Inject; import javax.inject.Named; -import org.jclouds.encryption.internal.Base64; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.http.HttpRequest; +import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.rest.MapBinder; import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.util.Preconditions2; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; import com.google.common.collect.ForwardingObject; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -61,7 +63,7 @@ public class CreateServerOptions implements MapBinder { public File(String path, byte[] contents) { this.path = checkNotNull(path, "path"); - this.contents = Base64.encodeBytes(checkNotNull(contents, "contents")); + this.contents = CryptoStreams.base64(checkNotNull(contents, "contents")); checkArgument( path.getBytes().length < 255, String.format("maximum length of path is 255 bytes. Path specified %s is %d bytes", path, @@ -182,7 +184,7 @@ public class CreateServerOptions implements MapBinder { if (keyName != null) server.key_name = keyName; if (userData != null) - server.user_data = Base64.encodeBytes(userData); + server.user_data = CryptoStreams.base64(userData); if (securityGroupNames.size() > 0) { server.securityGroupNames = Sets.newLinkedHashSet(); for (String groupName : securityGroupNames) { diff --git a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/filters/RequestAuthenticator.java b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/filters/RequestAuthenticator.java index c155d67193..7b424b46dc 100644 --- a/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/filters/RequestAuthenticator.java +++ b/labs/fgcp/src/main/java/org/jclouds/fujitsu/fgcp/filters/RequestAuthenticator.java @@ -42,8 +42,8 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import org.jclouds.Constants; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.date.TimeStamp; -import org.jclouds.encryption.internal.Base64; import org.jclouds.fujitsu.fgcp.reference.RequestParameters; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; @@ -205,7 +205,7 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner { try { signer.update(stringToSign.getBytes(Charsets.UTF_8)); - signed = Base64.encodeBytes(signer.sign()).replace("\n", "\r\n"); + signed = CryptoStreams.base64(signer.sign()).replace("\n", "\r\n"); // signed = CryptoStreams.base64(signer.sign()); } catch (SignatureException e) { throw new HttpException("error signing request", e); @@ -224,7 +224,7 @@ public class RequestAuthenticator implements HttpRequestFilter, RequestSigner { String signatureData = String.format("%s&%s&%s&%s", timezone, expires, signatureVersion, signatureMethod); - String accessKeyId = Base64.encodeBytes(signatureData.getBytes(Charsets.UTF_8)); + String accessKeyId = CryptoStreams.base64(signatureData.getBytes(Charsets.UTF_8)); return accessKeyId.replace("\n", "\r\n"); } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/binders/BindLaunchSpecificationToFormParamsTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/binders/BindLaunchSpecificationToFormParamsTest.java index f6f1f93c23..3600ee9c69 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/binders/BindLaunchSpecificationToFormParamsTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/binders/BindLaunchSpecificationToFormParamsTest.java @@ -23,8 +23,8 @@ import static org.testng.Assert.assertEquals; import java.net.UnknownHostException; import org.jclouds.aws.ec2.domain.LaunchSpecification; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.ec2.domain.InstanceType; -import org.jclouds.encryption.internal.Base64; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; @@ -54,7 +54,7 @@ public class BindLaunchSpecificationToFormParamsTest { assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro", "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.UserData", - Base64.encodeBytes("hello".getBytes()))); + CryptoStreams.base64("hello".getBytes()))); } @Test diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index 5efc2db5cf..7efa88908e 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -43,6 +43,7 @@ import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.domain.LoginCredentials; import org.jclouds.ec2.compute.EC2TemplateBuilderTest; import org.jclouds.ec2.compute.domain.EC2HardwareBuilder; @@ -53,7 +54,6 @@ import org.jclouds.ec2.compute.strategy.CreateKeyPairAndSecurityGroupsAsNeededAn import org.jclouds.ec2.domain.BlockDeviceMapping; import org.jclouds.ec2.domain.KeyPair; import org.jclouds.ec2.options.RunInstancesOptions; -import org.jclouds.encryption.internal.Base64; import org.jclouds.scriptbuilder.domain.Statements; import org.testng.annotations.Test; @@ -383,7 +383,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT assertEquals( customize.buildFormParameters().entries(), ImmutableMultimap. of("InstanceType", size.getProviderId(), "SecurityGroup.1", "group", - "KeyName", systemGeneratedKeyPairName, "UserData", Base64.encodeBytes("hello".getBytes())).entries()); + "KeyName", systemGeneratedKeyPairName, "UserData", CryptoStreams.base64("hello".getBytes())).entries()); assertEquals(customize.buildMatrixParameters(), ImmutableMultimap. of()); assertEquals(customize.buildRequestHeaders(), ImmutableMultimap. of()); assertEquals(customize.buildStringPayload(), null);