aws-v4-signer is a lightweight Kotlin-Multiplatform implementation of the AWS V4 signing algorithm required by many of the AWS services.
Compatible with Java 7+, Kotlin & Swift.
Add the latest aws-v4-signer Gradle dependency to your project
repository {
maven {
url 'https://dl.bintray.com/novoda-oss/maven'
}
}
dependencies {
implementation 'com.novoda:aws-v4-signer:0.0.2'
}
Generate an Xcode framework and link it to your project following the official documentation.
An example can be found under /samples/ios
.
./gradlew :aws-v4-signer:packForXCode
Swift:
let hash = Sha256Encoder().encode(value: "content as string")
let request = HttpRequest.Companion().create(method: "PUT", pathAndQuery: "?max-keys=2&prefix=J")
let signature = Signer.Builder()
.awsCredentials(awsCredentials: AwsCredentials(accessKey: "AKIAIOSFODNN7EXAMPLE", secretKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"))
.header(header: Header(name: "Host", value: "examplebucket.s3.amazonaws.com"))
.header(header: Header(name: "x-amz-date", value: "20120525T002453Z"))
.header(header: Header(name: "x-amz-content-sha256", value: hash))
.buildS3(request: request, contentSha256: hash)
.signature
Kotlin:
val hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
val request = HttpRequest.create("GET", "?max-keys=2&prefix=J")
val signature = Signer.Builder()
.awsCredentials(AwsCredentials(ACCESS_KEY, SECRET_KEY))
.header("Host", "examplebucket.s3.amazonaws.com")
.header("x-amz-date", "20130524T000000Z")
.header("x-amz-content-sha256", hash)
.buildS3(request, hash)
.signature
Swift:
let hash = Sha256Encoder().encode(value: "content as string")
let request = HttpRequest.Companion().create(method: "PUT", pathAndQuery: "/-/vaults/examplevault")
let signature = Signer.Builder()
.awsCredentials(awsCredentials: AwsCredentials(accessKey: "AKIAIOSFODNN7EXAMPLE", secretKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"))
.header(header: Header(name: "Host", value: "glacier.us-east-1.amazonaws.com"))
.header(header: Header(name: "x-amz-date", value: "20120525T002453Z"))
.header(header: Header(name: "x-amz-glacier-version", value: "2012-06-01"))
.buildGlacier(request: request, contentSha256: hash)
.signature
Kotlin:
val hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
val request = HttpRequest.create("PUT", "/-/vaults/examplevault")
val signature = Signer.Builder()
.awsCredentials(AwsCredentials(ACCESS_KEY, SECRET_KEY))
.header("Host", "glacier.us-east-1.amazonaws.com")
.header("x-amz-date", "20120525T002453Z")
.header("x-amz-glacier-version", "2012-06-01")
.buildGlacier(request, hash)
.signature