简体   繁体   English

Flutter Dart 以正确的方式进行哈希授权(SHA1、SHA256、Base64 格式)(php 到 dart)

[英]Flutter Dart Hashing in Proper Way to Authorization (SHA1, SHA256, Base64 format) (php to dart)

I am trying to integrate my flutter app with a payment api (called iyzico).我正在尝试将我的 flutter 应用程序与付款 api(称为 iyzico)集成。 Following the steps with http plugin and cyrpto plugin doesn't produce the desired solution.遵循http 插件cyrpto 插件的步骤不会产生所需的解决方案。 I wanted to ask you where is my mistake.我想问你我的错误在哪里。 I can not obtain the encodedstring property as desired.我无法获得所需的编码字符串属性。 There is a php code to understand it well.有一个 php 代码可以很好地理解它。 First we need to hash a string with following steps.首先,我们需要 hash 一个字符串,步骤如下。

Example on php:   $string = “some string”;

then we need to hash string with SHA1 (result should be in a raw binary format)然后我们需要 hash 字符串与 SHA1 (结果应该是原始二进制格式)

Example on php:  $hashedString=  sha1($string, true);

My solution like this up to now;到目前为止,我的解决方案是这样的;

 var string = utf8.encode("somestring");
 var hashedstring = sha1.convert(string);

Last step is that encode the hashed string to BASE64 format;最后一步是将散列字符串编码为 BASE64 格式;

Example on php:   $encodedString = base_64_encode($hashedString);

My solution was;我的解决方案是;

 Codec<String, String> stringToBase64 = utf8.fuse(base64);
 String encodedString = stringToBase64.encode(hashedstring.toString());

I don't know cryptology and crypto plugin very well and I think that ı could not get the value proper format.我不太了解密码学和加密插件,我认为我无法获得正确格式的值。 Thanks for now现在谢谢

This is how I generated the code challenge for PKCE.这就是我为 PKCE 生成代码挑战的方式。

import 'dart:convert';
import 'package:crypto/crypto.dart';

String encryptString(String value) =>
    base64UrlEncode(utf8.encode(sha256.convert(utf8.encode(value)).toString()));

Hope this may give some insights.希望这可以提供一些见解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM