@@ -25,6 +25,7 @@ import java.security.NoSuchProviderException
2525import java.security.Signature
2626import java.security.UnrecoverableKeyException
2727import java.security.cert.CertificateException
28+ import java.security.MessageDigest
2829import java.security.interfaces.RSAPublicKey
2930import androidx.core.content.edit
3031
@@ -1378,6 +1379,33 @@ class ReactNativeBiometricsSharedImpl(private val context: ReactApplicationConte
13781379 }
13791380 }
13801381
1382+ fun sha256 (data : String , inputEncoding : String? , promise : Promise ) {
1383+ try {
1384+ val encoding = inputEncoding ? : " utf8"
1385+ val dataBytes = decodeInputData(data, encoding)
1386+ if (dataBytes == null ) {
1387+ promise.resolve(Arguments .createMap().apply {
1388+ putString(" hash" , " " )
1389+ putString(" error" , " Invalid base64 data" )
1390+ })
1391+ return
1392+ }
1393+
1394+ val digest = MessageDigest .getInstance(" SHA-256" )
1395+ val hashBytes = digest.digest(dataBytes)
1396+ val hashBase64 = BiometricUtils .encodeBase64(hashBytes)
1397+
1398+ promise.resolve(Arguments .createMap().apply {
1399+ putString(" hash" , hashBase64)
1400+ })
1401+ } catch (e: Exception ) {
1402+ promise.resolve(Arguments .createMap().apply {
1403+ putString(" hash" , " " )
1404+ putString(" error" , e.message ? : " SHA256 failed" )
1405+ })
1406+ }
1407+ }
1408+
13811409 fun getKeyAttributes (keyAlias : String? , promise : Promise ) {
13821410 val actualKeyAlias = getKeyAlias(keyAlias)
13831411 debugLog(" getKeyAttributes called with keyAlias: ${keyAlias ? : " default" } , using: $actualKeyAlias " )
0 commit comments