flutter属于前端还是后端(kotlin比较flutter)

尝试了网上多种库和教程都没办法互解,JAVA代码如下,求个大佬帮忙用dart(Flutter)实现一个可以互解的aes加密代码packagecom.example.lib;importjavax.crypto.Cipher;importjavax.crypto.spec.IvParameterSpec;importjavax.crypto.spec.SecretKeySpec;public…

大家好,又见面了,我是你们的朋友全栈君。

尝试了网上多种库和教程都没办法互解,JAVA代码如下,求个大佬帮忙用dart(Flutter)实现一个可以互解的aes加密代码package com.example.lib;

import javax.crypto.Cipher;

import javax.crypto.spec.IvParameterSpec;

import javax.crypto.spec.SecretKeySpec;

public class Test {

static String keyStr = “620F15CFDB5C79C34B3940537B21EDA072E22F5D7151456DEC3932D7A2B22C53”;

static String ivStr = “85D7D7DA41E22C1A66C9C1BFC70A1088”;

public static void main(String[] args) {

String haha = encrypt(“哈哈!你好。”);//B7488CC936D5FF626F50900F99CEB2E13D99

decrypt(haha);

}

static String encrypt(String content) {

try {

byte[] ivByte = hex2byte(ivStr);

byte[] key = hex2byte(keyStr);

Cipher cipher = Cipher.getInstance(“AES/CFB/NoPadding”);

SecretKeySpec keySpec = new SecretKeySpec(key, “AES”);

IvParameterSpec ivSpec = new IvParameterSpec(ivByte);

cipher.init(1, keySpec, ivSpec);

byte[] doFinal = cipher.doFinal(content.getBytes(“UTF-8”));

System.out.println(“doFinale:” + byte2hex(doFinal));

return byte2hex(doFinal);

} catch (Exception e) {

e.printStackTrace();

return null;

}

}

static void decrypt(String content) {

try {

byte[] ivByte = hex2byte(ivStr);

byte[] contentByte = hex2byte(content);

byte[] key = hex2byte(keyStr);

Cipher cipher = Cipher.getInstance(“AES/CFB/NoPadding”);

SecretKeySpec keySpec = new SecretKeySpec(key, “AES”);

IvParameterSpec ivSpec = new IvParameterSpec(ivByte);

cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

byte[] result = cipher.doFinal(contentByte);

System.out.println(new String(result, “UTF-8”));

} catch (Exception e) {

e.printStackTrace();

}

}

public static byte[] hex2byte(String str) {

if (str == null) {

return null;

}

int length = str.length();

if (length % 2 == 1) {

return null;

}

byte[] bArr = new byte[length / 2];

for (int i = 0; i != length / 2; i++) {

int j = i * 2;

bArr[i] = (byte) Integer.parseInt(str.substring(j, j + 2), 16);

}

return bArr;

}

public static String byte2hex(byte[] bArr) {

String str = “”;

for (byte b : bArr) {

String hexString = Integer.toHexString(b & 255);

str = hexString.length() == 1 ? str + “0” + hexString : str + hexString;

}

return str.toUpperCase();

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/127422.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • navicat premium mac 激活码【2021.10最新】「建议收藏」

    (navicat premium mac 激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html2JTX0APX6F-eyJsaWNlbnNlSWQi…

    2022年3月30日
    1.2K
  • WIN10系统 Indirect Display 虚拟显示器之特殊应用

    WIN10系统 Indirect Display 虚拟显示器之特殊应用byfanxiushu2020-05-20转载或引用请注明原始作者。有人询问我是否可以实现这样一种功能:对windows输出的每一帧图像数据显示做一些特殊处理(比如球形桌面,曲面化等特效),然后再显示到显示器上。而且还不止一个人这样咨询过,虽然我不大清楚这种需求具体用在何处,估计也是一些特殊场所。这种需求,最先想到的,也最直观的想法就是能否给显卡驱动添加一个过滤驱动,然后拦截图像数据,然后再做些特殊处理。可惜想法是美好的,却是难以实现的,甚至是不大可能实现的。首先windows中就没显卡过

    2022年8月21日
    3
  • 自己工作用到的 linux添加路由的方法

    自己工作用到的 linux添加路由的方法linux下添加路由的方法一、查看及添加临时路由1.查看路由(linux下)[root@nfs~]#route#同netstat-rnKernelIProutingtableDestinationGatewayGenmaskFlagsMetricRefUseIface192.168.90.2*255.255.255.255UH00

    2022年10月4日
    0
  • MBUS协议_sbus协议

    MBUS协议_sbus协议在前面关于MBus协议的描述中,个人觉得在描述TSS721部分存在不容易理解的地方,总觉得还可以说的更清楚点,在实际使用中我又发现TSS721的一款替代芯片,在这里作个详细的说明,可以加深对MBus协议实现的理解和TSS721部分的理解。2013年9月10日–推动高能效创新的安森美半导体(ONSemiconductor,美国纳斯达克上市代号:ONNN)推出一款新的集成…

    2022年10月15日
    0
  • pycharm的背景颜色设置_css中设置背景颜色

    pycharm的背景颜色设置_css中设置背景颜色1.打开PyCharm–>File–>Setting.2.更改为你想要的背景颜色

    2022年8月29日
    0
  • php://input allow_url_include,DVWA设置PHP函数allow_url_include:已禁用

    php://input allow_url_include,DVWA设置PHP函数allow_url_include:已禁用DatabaseSetupClickonthe‘Create/ResetDatabase’buttonbelowtocreateorresetyourdatabase.Ifyougetanerrormakesureyouhavethecorrectusercredentialsin:C:\XAMPP\htdocs\dvwa/config/c…

    2022年7月21日
    11

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号