使用密钥加密、解密实例

这是一个关于如何在Java中使用DES(Data Encryption Standard)进行加密和解密的实例教程。代码涵盖了创建密钥、加密数据和解密数据的步骤。
摘要由CSDN通过智能技术生成

package com.xiaohe.mianshi1;

import java.io.IOException;
import java.security.SecureRandom;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;

import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;

public class DesUtil {
private final static String DES = “DES”;

public static void main(String[] args) {
    String data = "我爱你!!";
    String key = "123116爱11";
    System.out.println(enctypt(data, key));

    System.out.println(decrypt(enctypt(data, key), key));
}

public static String enctypt(String data, String key) {
    byte[] bt = encrypt(data.getBytes(), key.getBytes());
    String strs = new BASE64Encoder().encode(bt);
    return strs;
}

public static String decrypt(String data, String key) {
    System.out.println("data++++" +
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值