public abstract class ApplicationAuthInfo extends Object implements Parcelable
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
ApplicationAuthInfo() |
Modifier and Type | Method and Description |
---|---|
static ApplicationAuthInfo |
create(String hash,
long creationTimestampSec)
Creates a new
ApplicationAuthInfo |
abstract long |
getCreationTimestampSec()
The hash creation timestamp, in seconds since 1.1.1970, in UTC timezone.
|
abstract String |
getHash()
A string constructed with the appId, creation timestamp and the app secret,
with the following structure:
hs256(appId +
ApplicationAuthInfo.getCreationTimestampSec() ), signed with the application secret. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
describeContents, writeToParcel
public abstract String getHash()
ApplicationAuthInfo.getCreationTimestampSec()
), signed with the application secret.
A sample code to generate this hash, should be something like:
private static String signedHash(String apiKey, // Your API Key
long creationTimeSec, // Creation timestamp, in seconds since 1970, UTC timezone
String secretKey){ // Your Secret Key
try{
Mac mac = Mac.getInstance("HmacSHA384");
Charset ascii = Charset.forName("US-ASCII");
mac.init(new SecretKeySpec(secretKey.getBytes(ascii), mac.getAlgorithm()));
String apiKey64 = Base64.encodeToString(apiKey.getBytes(ascii), Base64.NO_WRAP);
String data = apiKey64 + "." + expirationInSeconds;
byte[] rawHash = mac.doFinal(data.getBytes(ascii));
// Encode into a hexadecimal string
StringBuilder hash = new StringBuilder();
for (int i = 0; i < rawHash.length; ++i){
hash.append(String.format("%02x", rawHash[i]));
}
return hash.toString();
} catch (NoSuchAlgorithmException | InvalidKeyException e){
throw new IllegalStateException("HmacSHA256 and US-ASCII must be supported", e);
}
}
public abstract long getCreationTimestampSec()
public static ApplicationAuthInfo create(String hash, long creationTimestampSec)
ApplicationAuthInfo
hash
- the hash. See ApplicationAuthInfo.getHash()
creationTimestampSec
- the creation timestamp, in seconds since epochApplicationAuthInfo
instance