首页 > 编程语言 > app直播源码,android AES加密解密实现

app直播源码,android AES加密解密实现

时间:2023-10-18 14:25:14浏览次数:30  
标签:AES Base64 app deskey Cipher byte data 源码 cipher

 app直播源码,android AES加密解密实现

import android.util.Base64;
import android.util.Log;
 
import java.security.Key;
 
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.IvParameterSpec;
 
/**
 * Created by Jane on 2017/10/10.
 */
 
public class CryptoTools {
    public static final String keyStr = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4";
    private static byte[] key= Base64.decode(keyStr.getBytes(),Base64.DEFAULT);
    private static byte[] keyiv = { 1, 2, 3, 4, 5, 6, 7, 8 };
    /**
     * ECB加密,不要IV
     * @param data 明文
     * @return Base64编码的密文
     * @throws Exception
     */
    public static byte[] des3EncodeECB(byte[] data)
            throws Exception {
        Key deskey = null;
        DESedeKeySpec spec = new DESedeKeySpec(key);
        SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
        deskey = keyfactory.generateSecret(spec);
        Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, deskey);
        byte[] bOut = cipher.doFinal(data);
        return bOut;
    }
 
    /**
     * ECB解密,不要IV
     * @param data Base64编码的密文
     * @return 明文
     * @throws Exception
     */
    public static byte[] ees3DecodeECB(byte[] data)
            throws Exception {
        Key deskey = null;
        DESedeKeySpec spec = new DESedeKeySpec(key);
        SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
        deskey = keyfactory.generateSecret(spec);
        Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding");
        Log.i("des", "decode init before");
        cipher.init(Cipher.DECRYPT_MODE, deskey);
        Log.i("des", "decode init after" + new String(data,"UTF-8"));
        byte[] bOut = cipher.doFinal(data);
        Log.i("des", "decode doFinal after");
        return bOut;
 
    }
 
    /**
     * CBC加密
 
     * @param data 明文
     * @return Base64编码的密文
     * @throws Exception
     */
    public static byte[] des3EncodeCBC( byte[] data)
            throws Exception {
        Key deskey = null;
        DESedeKeySpec spec = new DESedeKeySpec(key);
        SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
        deskey = keyfactory.generateSecret(spec);
        Cipher cipher = Cipher.getInstance("desede" + "/CBC/PKCS5Padding");
        IvParameterSpec ips = new IvParameterSpec(keyiv);
        cipher.init(Cipher.ENCRYPT_MODE, deskey, ips);
        byte[] bOut = cipher.doFinal(data);
        return bOut;
    }
 
    /**
     * CBC解密
 
     * @param data Base64编码的密文
     * @return 明文
     * @throws Exception
     */
    public static byte[] des3DecodeCBC(byte[] data)
            throws Exception {
 
        Key deskey = null;
        DESedeKeySpec spec = new DESedeKeySpec(key);
        SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
        deskey = keyfactory.generateSecret(spec);
        Cipher cipher = Cipher.getInstance("desede" + "/CBC/PKCS5Padding");
        IvParameterSpec ips = new IvParameterSpec(keyiv);
        cipher.init(Cipher.DECRYPT_MODE, deskey, ips);
        byte[] bOut = cipher.doFinal(data);
        return bOut;
 
    }
}
 
 
加密:
 byte[] temp = CryptoTools.des3EncodeECB(getString(R.string.app_url_use).getBytes("UTF-8"));
String  message = new String(Base64.encode(temp, Base64.DEFAULT),"UTF-8");
解密:
byte[] tmpt = Base64.decode(getString(R.string.app_url_use).getBytes("UTF-8"), Base64.DEFAULT);
tmpt = CryptoTools.ees3DecodeECB(tmpt);
String str = new String(tmpt, "UTF-8");
 

​以上就是app直播源码,android AES加密解密实现, 更多内容欢迎关注之后的文章

 

标签:AES,Base64,app,deskey,Cipher,byte,data,源码,cipher
From: https://www.cnblogs.com/yunbaomengnan/p/17772082.html

相关文章

  • HTTP文件断点续传原理解析(源码)
    生活中,有许多事物,在没有被揭开面纱之前,我们往往会觉得很神秘很高深,认为它一定很难,进而望而却步,失去了解它的机会。然而,很多事,只要我们自己能沉下心来,细细研究,那些神秘高深的,也会变得简单明了。"HTTP文件断点续传"就是这样一个好例子,深入了解背后之理,“HTTP文件断点续传原理”其实......
  • 7×24无人值守直播推流软件开发实战,揭开视频推流的底层原理(附源码)
    一、前言你有看到过那种不间断型的、循环播放视频音乐的直播间吗?或者那种直播播放电影的直播间?还有层出不穷的文章,类似如下标题:“如何搭建一个24小时不间断的直播间?躺入xxxx元!”“24小时电影直播间,每天到账xxx~xxxx,不出镜副业,人人可做!”“50块的云服务器直播推流让我月入过千......
  • (二)AppScan使用教程
     一、为什么要做安全测试一)背景概述随着互联网应用的普及,软件安全性越来越重要了。公司的产品在线上有些小的功能性Bug,可能就是体验性不好,引发用户的一些吐槽,损失一点用户,问题不大,可以不断改进。但是如果产品有高危漏洞,不小心被黑客袭击,导致服务器瘫痪或资金损失,重要数据泄......
  • [LeetCode] 2530. Maximal Score After Applying K Operations
    Youaregivena 0-indexed integerarray nums andaninteger k.Youhavea startingscore of 0.Inone operation:chooseanindex i suchthat 0<=i<nums.length,increaseyour score by nums[i],andreplace nums[i] with ceil(nums[i]/3).......
  • 7×24无人值守直播推流软件开发实战,一文为你揭开视频推流的底层原理(附源码)
    一、前言你有看到过那种不间断型的、循环播放视频音乐的直播间吗?或者那种直播播放电影的直播间?还有层出不穷的文章,类似如下标题:“如何搭建一个24小时不间断的直播间?躺入xxxx元!”“24小时电影直播间,每天到账xxx~xxxx,不出镜副业,人人可做!”“50块的云服务器直播推流让我月入过千?......
  • Sentinel源码改造,实现Nacos双向通信!
    SentinelDashboard(控制台)默认情况下,只能将配置规则保存到内存中,这样就会导致SentinelDashboard重启后配置规则丢失的情况,因此我们需要将规则保存到某种数据源中,Sentinel支持的数据源有以下这些:然而,默认情况下,Sentinel和数据源之间的关系是单向数据通讯的,也就是只能先在数......
  • Go - Using Templates for Go Web Applications
    Problem: YouwanttouseGo’stemplatingsystemtocreateawebapplication.Solution: Usethehtml/templatepackagetocreateawebapplication. packagemainimport("html/template""net/http")funchello......
  • 【Azure Logic App】使用Outlook.com发送邮件遇到429报错
    问题描述在LogicApp中使用Outlook.com组件发送邮件,遇见了outlookconnection报429的错误{"error":{"code":"ErrorExceededMessageLimit","message":"Cannotsendmail.DailyMessage/Recipientlimitexceeded.Followtheinstructionsinyo......
  • 【Azure Logic App】使用Outlook.com发送邮件遇到429报错
    问题描述在LogicApp中使用Outlook.com组件发送邮件,遇见了outlookconnection报429的错误{"error":{"code":"ErrorExceededMessageLimit","message":"Cannotsendmail.DailyMessage/Recipientlimitexceeded.Followtheinstructionsinyour......
  • react native app 图标在安卓上内容被切割问题记录
    问题背景:reactnative开发app,设置的app图标在安卓中会被切割,导致周围的留白被切掉,看起来很奇怪。甚至有些文字内容被切割掉,显示不全。在不同手机上,icon可能会被切割成各种圆角,如果留白不够,内容可能会被切割。在iOS上icon也有相应的规范,比如需要1024尺寸等。解决方法:在查找......