17

Hashing Value (String or Int OR etc...) in Flutter ## Heading ##

I have Value like "Almahery"

How to Hash in in SHA 256 ?

Muhammad Ashraf
  • 3,323
  • 2
  • 12
  • 19

2 Answers2

46
  1. Import (Crypto) :

     import 'package:crypto/crypto.dart';
    
  2. Then add this code:

     var bytes1 = utf8.encode("Almahery");         // data being hashed
     var digest1 = sha256.convert(bytes1);         // Hashing Process
     print("Digest as bytes: ${digest1.bytes}");   // Print Bytes
     print("Digest as hex string: $digest1");      // Print After Hashing
    
Dharman
  • 30,962
  • 25
  • 85
  • 135
Muhammad Ashraf
  • 3,323
  • 2
  • 12
  • 19
1

let you want convert apple to SHA256 String

import 'package:crypto/crypto.dart';
var appleInBytes = utf8.encode("apple");
String value = sha256.convert(appleInBytes);
print(value.toString());
 |
 |
\|/
result
===>  "3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b"
Sonu kumar
  • 351
  • 3
  • 7