首页 > 其他分享 >使用Flink进行MD5加密

使用Flink进行MD5加密

时间:2024-05-22 11:09:30浏览次数:11  
标签:Flink 加密 String flink new org apache import MD5

package com.huft.flk117.test;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.serialization.SimpleStringEncoder;
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.connector.file.sink.FileSink;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.DefaultRollingPolicy;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;

//使用Flink进行MD5加密
//1. 读取源文件 2.MD5加密 3.加密内容写入目标文件
public class Md5Demo {
public static void main(String[] args) throws Exception {
// String password = "15057630319";
// String encryptedPassword = md5(password);
// System.out.println("MD5 Encrypted Password: " + encryptedPassword);
t();
}

public static void t() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

    env.setParallelism(1);

   // env.getConfig().setDeploymentOption(ExecutionConfig.DeploymentOptions.BATCH);

    FileSource<String> fileSource = FileSource
            .forRecordStreamFormat(
                    new TextLineInputFormat(),
                    new Path("D:/temp/p.txt")
            )
            .build();

    DataStreamSource<String> ds = env.fromSource(fileSource, WatermarkStrategy.noWatermarks(), "filesource");

    SingleOutputStreamOperator<String> map = ds.map(s -> md5(s));

    FileSink<String> sink = FileSink
            .forRowFormat(new Path("D:/temp/p1.txt"), new SimpleStringEncoder<String>("UTF-8"))
            .withRollingPolicy(
                    DefaultRollingPolicy.builder()
                            .withRolloverInterval(Duration.ofMinutes(15))
                            .withInactivityInterval(Duration.ofMinutes(5))
                            .withMaxPartSize(MemorySize.ofMebiBytes(1024))
                            .build())
            .build();

    map.sinkTo(sink);

    //map.print();
    env.execute();

}
public static String toHexString(byte[] bytes) {
    StringBuilder hexString = new StringBuilder();
    for (byte b : bytes) {
        String hex = Integer.toHexString(0xff & b);
        if (hex.length() == 1) {
            hexString.append('0');
        }
        hexString.append(hex);
    }
    return hexString.toString();
}

public static String md5(String input) {
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] messageDigest = md.digest(input.getBytes());
        return toHexString(messageDigest);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}

}

标签:Flink,加密,String,flink,new,org,apache,import,MD5
From: https://www.cnblogs.com/huft/p/18205790

相关文章

  • 文件加密软件有什么用?企业必须安装么?
    文件加密软件在企业中的应用是为了加强信息安全管理,保障核心资料的安全。这种软件的核心功能是对企事业单位的文件进行加密,使得无权限人员即使获取了文件也无法阅读内容,有效防止信息泄露。那么,文件加密软件到底有何用处,企业必须使用吗?让我们一探究竟。 文件加密软件的用处......
  • 一个使用Python加密连接Elasticsearch的简单封装
    依赖:elasticsearch==7.17.9eshelpercore.py:#!/usr/bin/python3#coding=utf-8importdatetimeimportosimportsslfromelasticsearchimportElasticsearchdefget_env()->str:#这里指定查询的环境索引return"uat"defget_output_file_pat......
  • Flink富函数
      富函数是DataStreamAPI提供的函数接口,Flink的函数都有它的Rich版本,它与其他函数不同的是,富函数可以获取到运行环境上下文,初始化参数,拥有生命周期方法等,可通过它进行自定义复杂功能。我们常见的如RichMapFunction、RichFilterFunction等。    富函数的生命周期主要通过......
  • c2隐藏&流量加密
    c2隐藏&流量加密参考链接参考文章:https://webxxe.cn/index.php/archives/238/c2profile随机生成脚本:https://github.com/threatexpress/random_c2_profilehttps://github.com/RedSiege/C2concealerC2concealer使用:https://www.freebuf.com/articles/network/330713.html......
  • HLS视频加密,让您的视频内容更安全!
    **背景介绍**HLS视频加密是一种基于HTTPLiveStreaming(HLS)协议的加密技术。它的核心思想是将视频切片进行加密处理,在客户端播放时需要先获取解密密钥才能正常偶发。通过这种方式,HLS加密可以有效防止未经授权的第三方窃取视频内容,从而保障了视频内容的版权和安全。数据万象媒体......
  • 3DES加密、解密工具类,有需要的直接cv大法拿去用吧
    package你的类路径;importcn.hutool.core.codec.Base64;importjavax.crypto.BadPaddingException;importjavax.crypto.Cipher;importjavax.crypto.IllegalBlockSizeException;importjavax.crypto.NoSuchPaddingException;importjavax.crypto.spec.SecretKeySpec;importjav......
  • python 国密sm2(C1C3C2) sm4(CBC) 加密 解密
    fromgmssl.sm4importCryptSM4,SM4_ENCRYPT,SM4_DECRYPTimportbinasciiimportbase64fromgmsslimportsm2,func#GMSSLforPython#安装pipinstallgmssl#keycode='101231221289195374403401962572899'key='1012312212891953'iv=......
  • 某东h5st4.7 加密参数(二)
    接着上一篇文章,由于最近比较忙,没有时间看。今天有时间看看上一篇没有说完的其他加密参数。仅供学习交流!1、fp的生成,搜索关键词fingerprint,即可查看到生成位置调试可以找到生成位置2、请求获取tkalgo中参数expandParams,如下图调试可以获取到参数expandParams从此可......
  • 正式开启全站HTTPS加密之旅
    Tips:当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解`正式开启全站HTTPS加密之旅日期:2017-7-14阿珏谈天说地浏览:2158次评论:0条经过有段时间的内测,博客正式开启全站https。建站到......
  • 如何自动(定时/间隔/重复)执行 同步文件、备份打包加密压缩文件
    首先,需要用到的这个工具:度娘网盘提取码:qwu2蓝奏云提取码:2r1z 参考下列两个之前发布的教程结合使用即可:《快捷自由定时重启、注销、关机》《如何从多个文件夹内转移全部文件(忽略文件夹的结构)(进行复制)(再打包)》就是先设定好勾选对'来源路径’Zip打包,并且勾选备份模式备份......