基于JPBC的无证书聚合签名方案实现

基于JPBC的无证书聚合签名方案实现

摘要

一开始签名方案是基于PKI的,无证书签名起源于 基于身份密码体制, 2009 年第一篇无证书签名方案1被提出,随后出现了一些列方案2,3;包括无配对的无证书聚合签名方案4,更多内容参考文献5.

暂时没有看见无证书聚合签名方案实现相关的代码,本文基于JPBC库实现,使用方法可以参考B站视频。也可以使用C++和PBC库实现。

方案概述

本文方案是基于论文3描述的。

Setup
给定安全参数 κ ∈ Z \kappa \in Z κZ,KGC选择两个循环群 G 1 G_1 G1 G 2 G_2 G2,其阶均为素数 q q q G 1 G_1 G1 的生成元 P P P,计算可接受的配对 e : G 1 × G 1 → G 2 e:G_1×G_1→G_2 e:G1×G1G2 。 KGC 随机选择主密钥 s ∈ Z q ∗ s\in Z_q^\ast sZq ,设置 P p u b = s P P_{pub}=sP Ppub=sP ,选择加密哈希函数 H 1 : { 0 , 1 } ∗ → G 1 H_1:\{0,1\}^\ast→G_1 H1:{0,1}G1 , H 2 : { 0 , 1 } ∗ → G 1 H_2:\{0,1\}^\ast→G_1 H2:{0,1}G1, H 3 : { 0 , 1 } ∗ → Z q ∗ H_3:\{0,1\}^\ast→Z_q^\ast H3:{0,1}Zq. 系统参数为 { q , G 1 , G 2 , e , P , P p u b , H 1 , H 2 , H 3 } \{q,G_1,G_2,e,P,P_{pub},H_1,H_2,H_3 \} {q,G1,G2,e,P,Ppub,H1,H2,H3}, 主密钥是s。

PartialKeyGen:
给定用户身份 I D i ∈ { 0 , 1 } ∗ ID_i\in \{0,1\}^\ast IDi{0,1},KGC首先计算 Q I D i = H 1 ( I D i ) Q_{ID_i }=H_1 (ID_i) QIDi=H1(IDi)。 然后,它设置该用户的部分密钥 p s k I D i = s Q ( I D i ) psk_{ID_i }=sQ_(ID_i ) pskIDi=sQ(IDi)并将其通过安全通道传输给对应用户。 用户可以通过检查是否正确来检查其正确性 e ( p s k I D i , P ) = e ( Q I D i , P p u b ) e(psk_{ID_i },P)=e(Q_{ID_i },P_{pub}) e(pskIDi,P)=e(QIDi,Ppub)

UserKeyGen:
用户 I D i ID_i IDi随机选择值 x I D i ∈ Z q ∗ x_{ID_i }\in Z_q^\ast xIDiZq作为他的用户私钥 u s k I D i usk_{ID_i } uskIDi,并且计算用户公钥 u p k I D i = x I D i P upk_{ID_i}=x_{ID_i } P upkIDi=xIDiP

Sign:
对于消息 m i ∈ 0 , 1 ∗ m_i∈{0,1}^\ast mi0,1,选择状态信息 ∆ ∆ (选择公开参数作为状态信息),具有 I D i ID_i IDi身份的签名者执行以下步骤:

  1. 选择随机数 r i ∈ Z q ∗ r_i∈Z_q^\ast riZq并且计算 U i = r i P ∈ G 1 U_i=r_i P∈G_1 Ui=riPG1.
  2. 计算 Q = H 2 ( ∆ ) , h i = H 3 ( m i , I D i , u p k I D i , U i ) Q=H_2(∆),h_i=H_3(m_i,ID_i,upk_{ID_i},U_i) Q=H2(),hi=H3(mi,IDi,upkIDi,Ui)
  3. 计算 V i = p s k I D i + r i ⋅ Q + h i ⋅ x i ⋅ P p u b V_i=psk_{ID_i }+r_i⋅Q+h_i⋅x_i⋅P_{pub} Vi=pskIDi+riQ+hixiPpub.

输出 ( U i , V i ) (U_i,V_i ) (Ui,Vi)作为 m i m_i mi的签名。

Verify
给定一个消息 m i m_i mi签名 ( U i , V i ) (U_i,V_i ) (Ui,Vi),其对应的身份为 I D i ID_i IDi和公钥 u p k I D i upk_{ID_i} upkIDi,计算 Q ( I D i ) = H 1 ( I D i ) , Q = H 2 ( ∆ ) Q_(ID_i )=H_1 (ID_i ),Q=H_2 (∆) Q(IDi)=H1(IDi),Q=H2() ,
h i = H 3 ( m i , I D i , u p k I D i , U i ) h_i=H_3 (m_i,ID_i,upk_{ID_i },U_i ) hi=H3(mi,IDi,upkIDi,Ui)
如果等式 e ( V i , P ) = e ( h i ⋅ u p k I D i + Q I D i , P p u b ) e ( U i , Q ) e(V_i,P)=e(h_i⋅upk_{ID_i }+Q_{ID_i },P_{pub} )e(U_i,Q) e(Vi,P)=e(hiupkIDi+QIDi,Ppub)e(Ui,Q) 成立,接收签名;否则拒绝。

Aggregate
任何人都可以充当聚合签名生成器, 对于n个用户的聚合集 { U 1 , … , U n } \{U_1,…,U_n\} {U1,,Un}其对应身份为 { I D 1 , … , I D n } \{ID_1,…,ID_n \} {ID1,,IDn}以及对应公钥 { u p k 1 , … , u p k n } \{upk_1,…,upk_n\} {upk1,,upkn},对应消息签名对为 { ( m 1 , σ 1 = ( U 1 , V 1 ) ) , … , ( m n , σ n = ( U n , V n ) ) } \{(m_1,σ_1=(U_1,V_1 )),…,(m_n,σ_n=(U_n,V_n))\} {(m1,σ1=(U1,V1)),,(mn,σn=(Un,Vn))},
聚合签名计算: V = ∑ i = 1 n V i V=∑_{i=1}^n V_i V=i=1nVi, 将 σ = ( U 1 , … , U n , V ) σ=(U_1,…,U_n,V) σ=(U1,,Un,V)作为聚合签名。

Aggregate-Verify
验证聚合签名 σ = ( U 1 , … , U n , V ) σ=(U_1,…,U_n,V) σ=(U1,,Un,V)由n个用户 { U 1 , … , U n } \{U_1,…,U_n\} {U1,,Un}身份为 { I D 1 , … , I D n } \{ID_1,…,ID_n\} {ID1,,IDn}和对应的公钥 { u p k 1 , … , u p k n } \{upk_1,…,upk_n\} {upk1,,upkn};关于消息 { m 1 , … , m n } \{m_1,…,m_n \} {m1,,mn} 验证者执行以下操作:
计算 Q I D i = H 1 ( I D i ) , Q = H 2 ( ∆ ) , h i = H 3 ( m i , I D i , u p k I D i , U i ) , i = 1 , … , n Q_{ID_i }=H_1 (ID_i ),Q=H_2 (∆),h_i=H_3 (m_i,ID_i,upk_{ID_i },U_i ),i=1,…,n QIDi=H1(IDi),Q=H2(),hi=H3(mi,IDi,upkIDi,Ui),i=1,,n.
验证: e ( V , P ) = e ( ∑ i = 1 n [ h i ⋅ u p k I D i + Q I D i ] , P p u b ) e ( ∑ i = 1 n U i , Q ) e(V,P)=e(∑_{i=1}^n [h_i⋅upk_{ID_i}+Q_{ID_i} ] ,P_{pub} )e(∑_{i=1}^n U_i ,Q) e(V,P)=e(i=1n[hiupkIDi+QIDi],Ppub)e(i=1nUi,Q).如果满足则通过;否则验证失败。

代码实现

整体思路, 将相关密钥信息作为文件保存(序列化后可以通过网络传输),根据方案不同的功能设计不同的函数。

关于文件a_181_603.properties的内容

type=a
q=98826429041171753291515535532523512299028170537954154869719707264887274916552228805607584116490046284509883309001532457986879277885241872021906840932513241346999389365188296460009947
h=32243626948934860887488490158437299489453513352745889246437755713701521031193083418924110592954582395114812811896992400310730276
r=3064991081731777546575510593831386635550174528483098623
exp2=181
exp1=127
sign1=-1
sign0=-1

代码

import it.unisa.dia.gas.jpbc.Element;
import it.unisa.dia.gas.jpbc.Pairing;
import it.unisa.dia.gas.plaf.jpbc.pairing.PairingFactory;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;public class CLAS {//生成公私钥对,并保存到文件中public static void Setup(String pairingParametersFileName, String pubParamFileName, String KGC_SK_FileName) {Pairing bp = PairingFactory.getPairing(pairingParametersFileName);//G1的生成元PElement P = bp.getG1().newRandomElement().getImmutable();//计算主私钥和公钥Element s = bp.getZr().newRandomElement().getImmutable();Element P_Pub = P.mulZn(s);Properties pubParamProp = new Properties();//后面对写的元素统一采用如下方法:首先将元素转为字节数组,然后进行Base64编码为可读字符串pubParamProp.setProperty("P", Base64.getEncoder().encodeToString(P.toBytes()));pubParamProp.setProperty("P_Pub", Base64.getEncoder().encodeToString(P_Pub.toBytes()));storePropToFile(pubParamProp, pubParamFileName);Properties param_s = new Properties();//私钥不存入公开参数中,由KGC自己保存param_s.setProperty("s", Base64.getEncoder().encodeToString(s.toBytes()));storePropToFile(param_s, KGC_SK_FileName);}//根据用户id生成私钥public static void PartialPrivateKeyGen(String pairingParametersFileName, String id, String KGC_SK_FileName) throws NoSuchAlgorithmException {Pairing bp = PairingFactory.getPairing(pairingParametersFileName);//使用HASH 将 id 转为QIDbyte[] idHash = HASH(id);Element QID = bp.getG1().newElementFromHash(idHash, 0, idHash.length).getImmutable();//从文件中读取 主私钥Properties mskProp = loadPropFromFile(KGC_SK_FileName);String sString = mskProp.getProperty("s");Element s = bp.getZr().newElementFromBytes(Base64.getDecoder().decode(sString)).getImmutable();  //Base64编码后对应的恢复元素的方法//计算用户私钥, 这里应该将私钥安全的传输给用户//方便模拟,统一存入一个文件中Element psk_ID = QID.powZn(s).getImmutable();Properties pskProp = new Properties();pskProp.setProperty("psk", Base64.getEncoder().encodeToString(psk_ID.toBytes()));storePropToFile(pskProp, id + ".properties");}//生成用户私钥public static void UserKeyGen(String pairingParametersFileName, String pubParamFileName, String id) {Pairing bp = PairingFactory.getPairing(pairingParametersFileName);//从文件中读取公钥Properties pkProp = loadPropFromFile(pubParamFileName);String PString = pkProp.getProperty("P");Element P = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(PString)).getImmutable();//生成随机数x,作为用户的私钥Element x = bp.getZr().newRandomElement().getImmutable();//计算用户公钥Element upk = P.mulZn(x);Properties userProp = new Properties();userProp.setProperty("usk", Base64.getEncoder().encodeToString(x.toBytes()));userProp.setProperty("upk", Base64.getEncoder().encodeToString(upk.toBytes()));storePropToFile(userProp, id + ".properties");}//签名public static Element[] Sign(String pairingParametersFileName, String pubParamFileName, String id, byte[] message) throws NoSuchAlgorithmException {Pairing bp = PairingFactory.getPairing(pairingParametersFileName);//获取公开参数Properties pubProp = loadPropFromFile(pubParamFileName);Element P = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(pubProp.getProperty("P"))).getImmutable();Element P_Pub = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(pubProp.getProperty("P_Pub"))).getImmutable();//获取用户自己的信息Properties userProp = loadPropFromFile(id + ".properties");Element upk = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(userProp.getProperty("upk"))).getImmutable();Element x = bp.getZr().newElementFromBytes(Base64.getDecoder().decode(userProp.getProperty("usk"))).getImmutable();Element psk = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(userProp.getProperty("psk"))).getImmutable();//选择随机数Element r = bp.getZr().newRandomElement();Element U = P.mulZn(r).getImmutable();//获取状态信息,将公开参数作为状态信息String p = pubProp.getProperty("P");String pPub = pubProp.getProperty("P_Pub");byte[] hash = HASH(p + pPub);Element Q = hashToG(bp, hash);// 计算m, id, upk,U组合的hash值byte[] res = hashCombination(message, id.getBytes(), upk.toBytes(), U.toBytes());Element h = hashToZ(bp, res);Element V = P_Pub.mulZn(x).mulZn(h).add(Q.mulZn(r)).add(psk).getImmutable();Element[] sigma = new Element[2];sigma[0] = U;sigma[1] = V;return sigma;}//验证public static boolean Verify(String pairingParametersFileName, String pubParamFileName, String id, byte[] message, Element[] sigma) throws NoSuchAlgorithmException {Pairing bp = PairingFactory.getPairing(pairingParametersFileName);//使用sha1 将 id 转为QIDbyte[] idHash = HASH(id);Element QID = bp.getG1().newElementFromHash(idHash, 0, idHash.length).getImmutable();//获取公开参数Properties pubProp = loadPropFromFile(pubParamFileName);Element P = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(pubProp.getProperty("P"))).getImmutable();Element P_Pub = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(pubProp.getProperty("P_Pub"))).getImmutable();//获取状态信息,将公开参数作为状态信息String p = pubProp.getProperty("P");String pPub = pubProp.getProperty("P_Pub");byte[] hash = HASH(p + pPub);Element Q = hashToG(bp, hash);//获取用户的公钥,Properties userProp = loadPropFromFile(id + ".properties");Element upk = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(userProp.getProperty("upk"))).getImmutable();// 计算m, id, upk,U组合的hash值byte[] res = hashCombination(message, id.getBytes(), upk.toBytes(), sigma[0].toBytes());Element h = hashToZ(bp, res);Element left = bp.pairing(sigma[1], P);Element right = bp.pairing(QID.add(upk.mulZn(h)), P_Pub).mul(bp.pairing(sigma[0], Q));return left.isEqual(right);}//聚合签名, U_1,U_2,...,U_n,Vpublic static Element[] Aggregate(List<Element[]> sigmaList) {Element[] res = new Element[sigmaList.size() + 1];Element[] init = sigmaList.get(0);res[0] = init[0];Element V = init[1];for (int i = 1; i < sigmaList.size(); i++) {res[i] = sigmaList.get(i)[0];V = V.add(sigmaList.get(1)[1]);}res[sigmaList.size()] = V;return res;}// 聚合签名验证public static boolean AggregateVerify(String pairingParametersFileName, String pubParamFileName, String[] idx, byte[][] message, Element[] sigma) throws NoSuchAlgorithmException {Pairing bp = PairingFactory.getPairing(pairingParametersFileName);Element[] QIDX = new Element[idx.length];for (int i = 0; i < idx.length; i++) {byte[] idHash = HASH(idx[i]);Element QID = bp.getG1().newElementFromHash(idHash, 0, idHash.length).getImmutable();QIDX[i] = QID;}//获取公开参数信息Properties pubProp = loadPropFromFile(pubParamFileName);Element P = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(pubProp.getProperty("P"))).getImmutable();Element P_Pub = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(pubProp.getProperty("P_Pub"))).getImmutable();String p = pubProp.getProperty("P");String pPub = pubProp.getProperty("P_Pub");byte[] hash = HASH(p + pPub);Element Q = hashToG(bp, hash);Element[] PKX = new Element[idx.length];for (int i = 0; i < idx.length; i++) {Properties userProp = loadPropFromFile(idx[i] + ".properties");Element upk = bp.getG1().newElementFromBytes(Base64.getDecoder().decode(userProp.getProperty("upk"))).getImmutable();PKX[i] = upk;}Element[] hx = new Element[idx.length];for (int i = 0; i < idx.length; i++) {byte[] res = hashCombination(message[i], idx[i].getBytes(), PKX[i].toBytes(), sigma[i].toBytes());Element h = hashToZ(bp, res);hx[i] = h;}Element left = bp.pairing(sigma[idx.length], P);Element U = sigma[0];for (int i = 1; i < idx.length; i++) {U = U.add(sigma[i]);}Element part = QIDX[0].add(PKX[0].mulZn(hx[0]));for (int i = 1; i < idx.length; i++) {part = part.add(QIDX[i].add(PKX[i].mulZn(hx[i])));}Element right = bp.pairing(part, P_Pub).mul(bp.pairing(U, Q));return left.isEqual(right);}//一种可行的组合方法public static byte[] hashCombination(byte[] message, byte[] id, byte[] upk, byte[] U) throws NoSuchAlgorithmException {int m_len = message.length, id_len = id.length, upk_len = upk.length, u_len = U.length;int total_len = m_len + id_len + upk_len + u_len;byte[] res = new byte[total_len];for (int i = 0; i < m_len; i++) {res[i] = message[i];}for (int i = 0; i < id_len; i++) {res[i + m_len] = id[i];}for (int i = 0; i < upk_len; i++) {res[i + m_len + id_len] = upk[i];}for (int i = 0; i < u_len; i++) {res[i + m_len + id_len + upk_len] = U[i];}MessageDigest instance = MessageDigest.getInstance("SHA-256");instance.update(res);return instance.digest();}public static void storePropToFile(Properties prop, String fileName) {try (FileOutputStream out = new FileOutputStream(fileName, true)) {prop.store(out, null);} catch (IOException e) {e.printStackTrace();System.out.println(fileName + " save failed!");System.exit(-1);}}public static Properties loadPropFromFile(String fileName) {Properties prop = new Properties();try (FileInputStream in = new FileInputStream(fileName)) {prop.load(in);} catch (IOException e) {e.printStackTrace();System.out.println(fileName + " load failed!");System.exit(-1);}return prop;}public static byte[] HASH(String content) throws NoSuchAlgorithmException {MessageDigest instance = MessageDigest.getInstance("SHA-1");instance.update(content.getBytes());return instance.digest();}public static Element hashToG(Pairing pb, byte[] code) {return pb.getG1().newElementFromHash(code, 0, code.length).getImmutable();}public static Element hashToZ(Pairing pb, byte[] code) {return pb.getZr().newElementFromHash(code, 0, code.length).getImmutable();}public static void main(String[] args) throws Exception {String pairingParametersFileName = "a_181_603.properties";String idAlice = "alice@example.com";String idBob = "bob@example.com";String pubParamFileName = "data/pub.properties";String KGCFileName = "data/kgc.properties";Setup(pairingParametersFileName, pubParamFileName, KGCFileName);PartialPrivateKeyGen(pairingParametersFileName, idAlice, KGCFileName);PartialPrivateKeyGen(pairingParametersFileName, idBob, KGCFileName);UserKeyGen(pairingParametersFileName, pubParamFileName, idAlice);UserKeyGen(pairingParametersFileName, pubParamFileName, idBob);String message_a = "Alice,This is a message from Alice!";String message_b = "Bob,This is a message from Bob!";Element[] sigma1 = Sign(pairingParametersFileName, pubParamFileName, idAlice, message_a.getBytes());Element[] sigma2 = Sign(pairingParametersFileName, pubParamFileName, idBob, message_b.getBytes());boolean result = Verify(pairingParametersFileName, pubParamFileName, idAlice, message_a.getBytes(), sigma1);System.out.println("Alice 验证签名通过? " + result);result = Verify(pairingParametersFileName, pubParamFileName, idBob, message_b.getBytes(), sigma2);System.out.println("Bob 验证签名通过? " + result);List<Element[]> sigmaList = new ArrayList<>();sigmaList.add(sigma1);sigmaList.add(sigma2);Element[] SIGMA = Aggregate(sigmaList);String[] idx = {idAlice, idBob};byte[][] message = {message_a.getBytes(), message_b.getBytes()};
//        message[0][1] = 1;//假如消息被篡改result = AggregateVerify(pairingParametersFileName, pubParamFileName, idx, message, SIGMA);System.out.println("聚合签名验证通过? " + result);}}

参考文献

  1. A new certificateless aggregate signature scheme

  2. Cryptanalysis and improvement of a certificateless aggregate signature scheme

  3. A certificateless aggregate signature scheme for healthcare wireless sensor network

  4. Efficient certificateless aggregate signcryption scheme without bilinear pairings

  5. Security issues in IoT applications using certificateless aggregate signcryption schemes: An overview

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/155789.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网工内推 | 字节原厂,正式编,网络工程师,最高30K*15薪

01 字节跳动 招聘岗位&#xff1a;网络虚拟化高级研发工程师 职责描述&#xff1a; 1、负责字节跳动虚拟网络产品的研发&#xff0c;包括但不局限于网络VPC、NAT、LB负载均衡等&#xff1b; 2、负责字节跳动网络基础平台的研发&#xff0c;包括但不局限于网络控制面系统、容器…

如何通过算法模型进行数据预测

当今数据时代背景下更加重视数据的价值&#xff0c;企业信息化建设会越来越完善&#xff0c;越来越体系化&#xff0c;以数据说话&#xff0c;通过数据为企业提升渠道转化率、改善企业产品、实现精准运营&#xff0c;为企业打造自助模式的数据分析成果&#xff0c;以数据驱动决…

Sentinel 系统规则 (SystemRule)

Sentinel 是面向分布式、多语言异构化服务架构的流量治理组件&#xff0c;主要以流量为切入点&#xff0c;从流量路由、流量控制、流量整形、熔断降级、系统自适应过载保护、热点流量防护等多个维度来帮助开发者保障微服务的稳定性。 SpringbootDubboNacos 集成 Sentinel&…

【Python 千题 —— 基础篇】2 的 N 次方

题目描述 题目描述 2 的 N 次方。输入一个整数 N&#xff0c;使用 for 循环计算 2 的 N 次方的值。 输入描述 输入一个整数值 N。 输出描述 输出 2 的 N 次方的值。 示例 示例 ① 输入&#xff1a; 20输出&#xff1a; 请输入一个整数 N: 20 2 的 20 次方的值是: 10…

sqlmap的使用笔记及示例

sqlmap的使用笔记 文章目录 sqlmap的使用笔记1. 目标2. 脱库2.1. 脱库&#xff08;补充&#xff09; 3. 其他3.1. 其他&#xff08;补充&#xff09; 1. 目标 操作作用必要示例-u指定URL&#xff0c;检测注入点sqlmap -u http://example.com/?id1-m指定txt&#xff0c;里面有…

PTA 7-50 完全二叉搜索树

7-50 完全二叉搜索树 超详细讲解&#xff0c;超详细讲解&#xff0c;超详细讲解&#xff01; 7-50 完全二叉搜索树 分数 30 全屏浏览题目 作者 陈越 单位 浙江大学 一个无重复的非负整数序列&#xff0c;必定对应唯一的一棵形状为完全二叉树的二叉搜索树。本题就要求你输…

Nacos介绍与使用

Nacos介绍与使用 文章目录 Nacos介绍与使用一. 什么是Nacos1 Nacos功能1.1 配置中心1.2 注册中心 2.为什么要使用Nacos 二.Nacos 部署安装1. Nacos 部署方式2. Nacos 安装3. 配置数据源4. 开启控制台授权登录&#xff08;可选&#xff09; 三. Nacos配置中心的使用1. 创建配置信…

2023年【T电梯修理】考试题及T电梯修理考试报名

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 T电梯修理考试题是安全生产模拟考试一点通总题库中生成的一套T电梯修理考试报名&#xff0c;安全生产模拟考试一点通上T电梯修理作业手机同步练习。2023年【T电梯修理】考试题及T电梯修理考试报名 1、【多选题】GB/T1…

python日志输出和命令行参数解析示例

代码包含日志终端输出、日志文件输出和命令行参数解析示例 主要功能&#xff0c;根据命令行参数复制对应比例的文件到指定的文件夹中&#xff0c;并输出相应日志 import os import random import shutil import logging import argparse def copy_random_files(input_folder, …

红队攻防之Goby反杀

若结局非我所愿&#xff0c;那就在尘埃落定前奋力一搏。 本文首发于先知社区&#xff0c;原创作者即是本人 一、弹xss 为了方便&#xff0c;本次直接使用 PhpStudy 进行建站&#xff0c;开启的web服务要为MySQLNginx&#xff0c;这里的 PhpStudy 地址为 http://x.x.x.x&…

线程池的异常处理机制

起因 一次开发过程中&#xff0c;送审之后向三方OA系统推送代办&#xff0c;其中由于优化的原因使用到线程池 ExecutorService todoMessageAsyncThread ThreadPoolManager.getThreadPool("todoMessageAsyncThreadPool");todoMessageAsyncThread.submit(() -> {…

【Leetcode Sheet】Weekly Practice 16

Leetcode Test 1334 阈值距离内邻居最少的城市(11.14) 有 n 个城市&#xff0c;按从 0 到 n-1 编号。给你一个边数组 edges&#xff0c;其中 edges[i] [fromi, toi, weighti] 代表 fromi 和 toi 两个城市之间的双向加权边&#xff0c;距离阈值是一个整数 distanceThreshold。…

Hibernate 一级缓存,二级缓存,查询缓存

概念&#xff1a; 1.什么是缓存呢&#xff1f; 缓存&#xff1a;是计算机领域的概念&#xff0c;它介于应用程序和永久性数据存储源之间。 缓存&#xff1a;一般人的理解是在内存中的一块空间&#xff0c;可以将二级缓存配置到硬盘。用白话来说&#xff0c;就是一个存储数据的…

Web前端—移动Web第三天(移动Web基础、rem、less、综合案例—极速问诊)

版本说明 当前版本号[20231120]。 版本修改说明20231120初版 目录 文章目录 版本说明目录移动 Web 第三天01-移动 Web 基础谷歌模拟器屏幕分辨率视口二倍图适配方案 02-rem简介媒体查询rem 布局flexible.jsrem 移动适配 03-less注释运算嵌套变量导入导出禁止导出 04-综合案例…

GNSS技术在灾害监测与应急响应中的关键作用

全球导航卫星系统&#xff08;GNSS&#xff09;技术在灾害监测与应急响应领域发挥着重要作用&#xff0c;为预防、监测和应对自然灾害提供了关键数据支持。本文将深入探讨GNSS技术在灾害监测与应急响应中的作用&#xff0c;并分析其对提高应对灾害能力的重要性。 一、GNSS在灾害…

android报错

&#xff08;gradle版本&#xff1a;7.5-all.zip; gradle插件&#xff1a;7.4.2&#xff1b;java:11) 报错1&#xff1a; java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode 2023-11-20 19:39:39.207 22390-22390 AndroidRuntime com…

InnoDB 的一次更新事务是怎么实现的?

大体流程&#xff1a; 步骤: 1.加载数据到缓存中&#xff08;Buffer Pool&#xff09;&#xff1a; 在进行数据更新时&#xff0c;InnoDB首先会在缓冲池&#xff08;Buffer Pool&#xff09;中查找该记录是否已经在内存中。如果记录不在内存中&#xff0c;会将需要更新的数据…

2021年03月 Scratch(二级)真题解析#中国电子学会#全国青少年软件编程等级考试

Scratch等级考试(1~4级)全部真题・点这里 一、单选题(共25题,每题2分,共50分) 第1题 小猫在沙漠中旅行好不容易找到了一杯水,初始位置如下图所示,下面哪个程序可以帮助它成功喝到水? A: B: C: D:

基于像素特征的kmeas聚类的图像分割方案

kmeans聚类代码 将像素进行聚类&#xff0c;得到每个像素的聚类标签&#xff0c;默认聚类簇数为3 def seg_kmeans(img,clusters3):img_flatimg.reshape((-1,3))# print(img_flat.shape)img_flatnp.float32(img_flat)criteria(cv.TERM_CRITERIA_MAX_ITERcv.TERM_CRITERIA_EPS,2…

stack和queue简单实现(容器适配器)

容器适配器 stack介绍stack模拟实现queue 介绍queue模拟实现deque stack介绍 stack模拟实现 以前我们实现stack&#xff0c;需要像list,vector一样手动创建成员函数&#xff0c;成员变量。但是stack作为容器适配器&#xff0c;我们有更简单的方法来实现它。 可以利用模板的强大…