Created
August 29, 2024 04:43
-
-
Save theapache64/79904d4b7d0e71ebd2cd7cd561fb268f to your computer and use it in GitHub Desktop.
X Signature Gen Test : https://developer.x.com/en/docs/authentication/oauth-1-0a/creating-a-signature
This file contains hidden or 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 org.apache.commons.codec.digest.HmacAlgorithms | |
import org.apache.commons.codec.digest.HmacUtils | |
import kotlin.io.encoding.Base64 | |
import kotlin.io.encoding.ExperimentalEncodingApi | |
// Guide : https://developer.x.com/en/docs/authentication/oauth-1-0a/creating-a-signature | |
@OptIn(ExperimentalStdlibApi::class, ExperimentalEncodingApi::class) | |
fun main() { | |
val baseString = | |
"POST&https%3A%2F%2Fapi.x.com%2F1.1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521" | |
val signingKey = "kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE" | |
val byteString = HmacUtils(HmacAlgorithms.HMAC_SHA_1, signingKey).hmac(baseString) | |
println("byteString: ${byteString.toHexString()} ") | |
println("base64: ${Base64.encode(byteString)} ") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment