![[Android][Kotlin]文字列をSHA-1でハッシュ化する方法](https://www.yukiiworks.com/wp-content/uploads/2019/04/kotlin.png)
はじめに
AndroidにてAPIを叩くときにSHA-1でパラメータをハッシュ化して送る必要があったのでその時のコードのメモ。
特に言いたいことはないのでコード載せます。
コード
以下コード。一応関数化してあります。
1 2 3 4 5 6 7 8 9 10 11 | fun hashSHA1String(target: String): String { val hashBytes = MessageDigest.getInstance("SHA-1").digest(target.toByteArray()) val hexChars = "0123456789ABCDEF" val result = StringBuilder(hashBytes.size * 2) hashBytes.forEach { val i = it.toInt() result.append(hexChars[i shr 4 and 0x0f]) result.append(hexChars[i and 0x0f]) } return result.toString() } |
SHA-1の部分をSHA-256にすればSHA-256でのハッシュ文字列も作れます。
以上です。
![[Android]Error while executing: am start -n XXX.....エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/10/android-studio-e1585186990750-300x159.jpg)
![[AWS]Node.jsでSSMパラメータストアの値を取得する](https://www.yukiiworks.com/wp-content/uploads/2020/03/aws-eyecatch-960x504-1-300x158.png)
![[Android][Kotlin]ToolBarのタイトルを消す方法](https://www.yukiiworks.com/wp-content/uploads/2019/10/android-studio-e1585186990750-150x150.jpg)
![[iOS13]ERROR ITMS-90785: “UIUserInterfaceStyle can’t be ‘light’. It can only be ‘Light’, ‘Dark’, or ‘Automatic’.エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/09/Xcode-150x150.png)
![[DB2]ペンディング状態の解除](https://www.yukiiworks.com/wp-content/uploads/2019/03/code1211IMGL1494_TP_V4-150x150.jpg)
![[Android]paddingしたListViewのスクロールバー位置の変更方法](https://www.yukiiworks.com/wp-content/uploads/2019/04/android-150x150.jpg)
![[AWS]Lambdaの環境変数をCLIコマンドで設定する](https://www.yukiiworks.com/wp-content/uploads/2020/04/lambda30-150x150.png)
