Created
August 8, 2015 00:30
-
-
Save akiradeveloper/76035c56551cd07cf9d1 to your computer and use it in GitHub Desktop.
S3Signerを試す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URI | |
import com.amazonaws.DefaultRequest | |
import com.amazonaws.auth.{SigningAlgorithm, BasicAWSCredentials} | |
import com.amazonaws.http.HttpMethodName | |
import com.amazonaws.services.s3.internal.{RestUtils, S3Signer} | |
import com.amazonaws.util.HttpUtils | |
import scala.collection.mutable | |
import collection.JavaConversions._ | |
/** | |
* Created by akira on 2015/08/08. | |
*/ | |
object ReqSignature { | |
def main(args: Array[String]): Unit = { | |
// GET Bucket | |
val orig = new DefaultRequest("s3") | |
orig.setHttpMethod(HttpMethodName.GET) | |
orig.setEndpoint(new URI("/")) | |
orig.setHeaders(mutable.HashMap( | |
"Host" -> "mybucket.s3.amazonaws.com", | |
"Date" -> "Fri, 07 Aug 2015 23:51:51 GMT" | |
)) | |
// orig.setParameters() | |
println(orig) | |
val signer = new S3Signer("GET", "/mybucket") | |
signer.sign(orig, new BasicAWSCredentials("a", "b")) | |
println(orig) | |
// signer.sign(orig, new BasicAWSCredentials("a", "b")) | |
//println(orig) | |
val canoS = RestUtils.makeS3CanonicalString( | |
"GET", | |
HttpUtils.appendUri(orig.getEndpoint.getPath, "/mybucket", true), | |
orig, | |
null) | |
// impossible! | |
val sig = signer.signAndBase64Encode(canoS, "b", SigningAlgorithm.HmacSHA1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment