【信息安全】密码学

news2024/9/23 1:31:09

信息验证遇到的问题Message Authentication

In the context of communications across a network, the following attacks can be identified.

泄密Disclosure

流量分析Traffic analysis

伪装Masquerade

Content modification

Sequence modification

Time modification

Source repudiation

Destination repudiation

Any message authentication or digital signature mechanism has two levels of functionality.

At the lower level, there must be some sort of function that produces an authenticator: a value to be used to authenticate a message.

This lower-level function is then used as a primitive in a higher-level authentication protocol that enables a receiver to verify the authenticity of a message.

Message Authentication Code (MAC)

An alternative authentication technique involves the use of a secret key to generate a small fixed-size block of data that is appended to the message.

This technique assumes that two communicating parties, say A and B, share a common secret key K. When A has a message to send to B, it calculates the MAC as a function of the message and the key:  

MAC based on Hash functions: HMAC

Digital Signatures

The most important development from the work on public-key cryptography is the digital signature.

The digital signature provides a set of security capabilities that would be difficult to implement in any other way.

The message is authenticated both in terms of source and in terms of data integrity.

Digital Signature Algorithm (DSA)

S-DES

class SDES:
    def __init__(self):
        self.P8_table = [6, 3, 7, 4, 8, 5, 10, 9]
        self.P10_table = [3, 5, 2, 7, 4, 10, 1, 9, 8, 6]

    def P8(self, key):
        k = key
        return [k[i - 1] for i in self.P8_table]

    def P10(self, key):
        k = key
        return [k[i - 1] for i in self.P10_table]

    def Shift(self, value):
        return value[1:5] + value[0:1] + value[6:10] + value[5:6]

    def generate_subkeys(self, key):
        key = self.P10(key)
        left = self.Shift(key[:5])
        right = self.Shift(key[5:])
        subkey1 = self.P8(left + right)
        left = self.Shift(left)
        right = self.Shift(right)
        left = self.Shift(left)
        right = self.Shift(right)
        subkey2 = self.P8(left + right)
        return subkey1, subkey2

    def IP(self, data):
        return [data[i - 1] for i in [2, 6, 3, 1, 4, 8, 5, 7]]

    def IP_inv(self, data):
        return [data[i - 1] for i in [4, 1, 3, 5, 7, 2, 8, 6]]

    def F(self, data, subkey):
        right = data
        right_expanded = [right[i - 1] for i in [4, 1, 2, 3, 2, 3, 4, 1]]
        xor_result = [subkey[i] ^ int(right_expanded[i]) for i in range(8)]
        sbox_result = self.sbox(xor_result)
        return sbox_result

    def F_K(self, data, subkey):
        left = data[:4]
        right = data[4:]
        right_F = self.F(right, subkey)
        xor_result = [int(left[i]) ^ int(right_F[i]) for i in range(4)]
        return xor_result+right

    def SW(self, data):
        return data[4:]+data[0:4]

    def sbox(self, data):
        sbox1 = [
            [1, 0, 3, 2],
            [3, 2, 1, 0],
            [0, 2, 1, 3],
            [3, 1, 3, 2]
        ]
        sbox2 = [
            [0, 1, 2, 3],
            [2, 0, 1, 3],
            [3, 0, 1, 0],
            [2, 1, 0, 3]
        ]
        row = int(''.join([str(data[0]), str(data[3])]), 2)
        col = int(''.join([str(data[1]), str(data[2])]), 2)
        return [int(x) for x in bin(sbox1[row][col])[2:].zfill(2) + bin(sbox2[row][col])[2:].zfill(2)]

    def encrypt(self, plaintext, key):
        key1, key2 = self.generate_subkeys(key)
        plaintext = self.IP(plaintext)
        plaintext = self.F_K(plaintext, key1)
        plaintext = plaintext[4:] + plaintext[:4]
        plaintext = self.F_K(plaintext, key2)
        return self.IP_inv(plaintext)

    def decrypt(self, ciphertext, key):
        key1, key2 = self.generate_subkeys(key)
        ciphertext = self.IP(ciphertext)
        ciphertext = self.F_K(ciphertext, key2)
        ciphertext = ciphertext[4:] + ciphertext[:4]
        ciphertext = self.F_K(ciphertext, key1)
        return self.IP_inv(ciphertext)


def ascii_to_binary_8(plaintext):
    binary_list = []
    for char in plaintext:
        ascii_value = ord(char)
        # Convert ASCII to binary, removing '0b' prefix
        binary_string = bin(ascii_value)[2:]
        binary_string = '0' * (8 - len(binary_string)) + \
            binary_string  # Ensure 10-bit length
        binary_list.append(binary_string)
    return binary_list


def binary_to_ascii(binary_list):
    plaintext = ""
    for binary_string in binary_list:
        binary = ''.join(str(bit) for bit in binary_string)
        # 将二进制字符串转换为整数
        ascii_value = int(binary, 2)
        # 将整数转换为字符,并添加到明文字符串中
        plaintext += chr(ascii_value)
    return plaintext


# 示例
plaintext = ('Network security encompasses all the steps taken to protect the integrity of a computer network and the '
             'data within it. Network security is important because it keeps sensitive data safe from cyber attacks '
             'and ensures the network is usable and trustworthy. Successful network security strategies employ '
             'multiple security solutions to protect users and organizations from malware and cyber attacks, '
             'like distributed denial of service')
key = '1100011110'
key = [int(i) for i in key]
s = SDES()
plaintext_binary = ascii_to_binary_8(plaintext)
print("明文:", plaintext_binary)
ciphertext = []
for binary_str in plaintext_binary:
    encrypted_text = s.encrypt(binary_str, key)
    ciphertext.append(encrypted_text)

print("密文:", ciphertext)

decrypted_text = []
for encrypted_text in ciphertext:
    decrypted_text.append(s.decrypt(encrypted_text, key))
print("解密后的明文(ASCII):", decrypted_text)
decrypted_text = binary_to_ascii(decrypted_text)
print("解密后的明文:", decrypted_text)

S-AES

公钥密码学Public-Key Cryptography

公钥密码学Public-Key Cryptography-CSDN博客

对称密钥分配Symmetric Key Distribution

Symmetric Encryption

For two parties A and B, key distribution can be achieved in a number of ways, as follows:

  1. A can select a key and physically deliver it to B.
  2. If A and B have previously and recently used a key, one party can transmit the new key to the other, encrypted using the old key.
  3. A third party can select the key and physically deliver it to A and B.
  4. If A and B each has an encrypted connection to a third party C, C can deliver a key on the encrypted links to A and B.

KTC(A key translation center)

Transfer symmetric keys for future communication between two entities, at least one of whom has the ability to generate or acquire symmetric keys by themselves. Entity A generates or acquires a symmetric key to be used as a session key for communication with B. A encrypts the key using the master key it shares with the KTC and sends the encrypted key to the KTC. The KTC decrypts the session key, re-encrypts the session key in the master key it shares with B, and either sends that re-encrypted session key to A (Figure a) for A to forward to B or sends it directly to B (Figure b).

KDC(A key distribution center)

Generate and distribute session keys. Entity A sends a request to the KDC for a symmetric key to be used as a session key for communication with B.  KDC generates a symmetric session key, and then encrypts the session key with the master key it shares with A and sends it to A. The KDC also encrypts the session key with the master key is shares with B and sends it to B (Figure c). Alternatively, KDC sends both encrypted key values to A, and A forwards the session key encrypted with the master key shared by the KDC and B to B (Figure d).

KDC vs KTC

kdc的密钥是第三方分发,ktc是用户自己产生密钥

非对称加密Asymmetric Encryption

If A wishes to communicate with B, the following procedure is employed:  

  1. A generates a public/private key pair {PUa, PRa} and transmits a message to B consisting of PUa and an identifier of A, IDA.  
  2. B generates a secret key, Ks, and transmits it to A, which is encrypted with A’s public key.  
  3. A computes D(PRa, E(PUa, Ks)) to recover the secret key. Because only A can decrypt the message, only A and B will know the identity of Ks.  
  4. A discards PUa and PRa and B discards PUa.

Secret Key Distribution with Confidentiality and Authentication

challenge and response

Distribution of Public Keys

Several techniques have been proposed for the distribution of public keys Public announcement Publicly available directory Public-key authority Public-key certificates

Public Announcement

The point of public-key encryption is that the public key is public. Thus, if there is some broadly accepted public-key algorithm, such as RSA, any participant can send his or her public key to any other participant or broadcast the key to the community. Anyone can forge such a public announcement.

Publicly Available Directory

A greater degree of security can be achieved by maintaining a publicly available dynamic directory of public keys. Maintenance and distribution of the public directory would have to be the responsibility of some trusted entity or organization.

  1. The authority maintains a directory with a {name, public key} entry for each participant.
  2. Each participant registers a public key with the directory authority. Registration would have to be in person or by some form of secure authenticated communication.
  3. A participant may replace the existing key with a new one at any time, either because of the desire to replace a public key that has already been used for a large amount of data, or because the corresponding private key has been compromised in some way.
  4. Participants could also access the directory electronically. For this purpose, secure, authenticated communication from the authority to the participant is mandatory.

Public-Key Authority

Stronger security for public-key distribution can be achieved by providing tighter control over the distribution of public keys from the directory.

Assume that a central authority maintains a dynamic directory of public keys of all participants.

Each participant reliably knows a public key for the authority, with only the authority knowing the corresponding private key.  

Step 6, Step 7: Challenge and Response

  1. A total of seven messages are required.
  2. However, the initial five messages need to be used only infrequently because both A and B can save the other’s public key for future use A technique known as caching
  3. Periodically, a user should request fresh copies of the public keys to ensure currency.
  4. The public-key authority could be somewhat of a bottleneck in the system.

公钥证书Public-Key Certificates

Certificates can be used by participants to exchange keys without contacting a public-key authority.

A certificate consists of a public key, an identifier of the key owner, and the whole block signed by a trusted third party.

The third party is a certificate authority, such as a government agency or a financial institution, that is trusted by the user community.  

Requirements

  1. Any participant can read a certificate to determine the name and public key of the certificate’s owner.
  2. Any participant can verify that the certificate originated from the certificate authority and is not counterfeit.
  3. Only the certificate authority can create and update certificates.
  4. 任何参与者都可以验证证书的时间有效性。 Any participant can verify the time validity of the certificate.

X.509 Certificates

一个证书的标准

X.509 has become universally accepted for formatting public-key certificates. X.509 certificates are used in most network security applications, including IP security, transport layer (TLS), and S/MIME. X.509 was initially issued in 1988. The standard was subsequently revised in 1993 to address some of the security. The standard is currently at edition eight, issued in 2016.

User Certificates generated by a CA have the following characteristics: Any user with access to the public key of the CA can verify the user public key that was certified. No party other than the CA can modify the certificate without this being detected. Because certificates are unforgeable, they can be placed in a directory without the need for the directory to make special efforts to protect them. A user can transmit his certificate directly to other users.

With many users, it may be more practical for there to be a number of CAs, each of which securely provides its public key to some fraction of the users. Now suppose that A has obtained a certificate from certification authority X1 and B has obtained a certificate from CA X2. If A does not securely know the public key of X2, then B’s certificate, issued by X2, is useless to A. A can read B’s certificate, but A cannot verify the signature.

If the two CAs have securely exchanged their own public keys, the following procedure will enable A to obtain B’s public key.

Step 1: A obtains from the directory the certificate of X2 signed by X1. Because A securely knows X1’s public key, A can obtain X2’s public key from its certificate and verify it by means of X1’s signature on the certificate.

Step 2: A then goes back to the directory and obtains the certificate of B signed by X2. Because A now has a trusted copy of X2’s public key, A can verify the signature and securely obtain B’s public key.  

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

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

相关文章

一、写给Android开发者之harmony入门

一、创建新项目 对比 android-studio:ability类似安卓activity ability分为两种类型(Stage模型) UIAbility和Extensionability(提供系统服务和后台任务) 启动模式 1、 singleton启动模式:单例 2、 multiton启动模式&#xff1…

学习Rust的第29天: cat in Rust

今天即将是这个系列的最后一次内容,我们正在catRust 中从 GNU 核心实用程序进行重建。cat用于将文件内容打印到STDOUT.听起来很容易构建,所以让我们开始吧。 GitHub 存储库:GitHub - shafinmurani/gnu-core-utils-rust 伪代码 function read(…

Django实验(远程访问+图片显示)

众所周知,Python除了不能生孩子什么都会。Python也是可以做web服务的。 Python做web有一个重点优势是:做一个快速的AI Demo。 第一步:安装一个版本5.0以上django 第二步:构建咱们的Django工程,我取名为BBQ django-adm…

基于 Ubuntu22.04 安装 SSH 服务

文章目录 一、Ubuntu22.04 安装 SSH 服务二、配置 OpenSSH(安全性)1. 更改 OpenSSH 端口2. 限制使用 SSH 登录尝试次数3. 禁止 SSH 以 root 身份连接 三、设置防火墙(UFW)锁定 SSH四、远程终端软件通过 SSH 连接 Ubuntu22.041. 远…

js api part4

其他事件 页面加载事件 外部资源(如图片、外联CSS和JavaScript等)加载完毕时触发的事件 原因:有些时候需要等页面资源全部处理完了做一些事情,老代码喜欢把 script 写在 head 中,这时候直接找 dom 元素找不到。 事件…

实测好评!微信自动回复消息神器!高效沟通拿捏住!

随着企业规模的扩大和客户数量的增加,有效管理和回复每一条消息变得越来越具有挑战性。今天,就给大家分享一个高效的自动回复消息神器——个微管理系统,让你能够轻松应对各种沟通需求。 1、自动通过好友,提高沟通效率 每当有新的…

AI神助攻!小白也能制作自动重命名工具~

我们平时从网上下载一些文件,文件名很多都是一大串字母和数字,不打开看看,根本不知道里面是什么内容。 我想能不能做个工具,把我们一个文件夹下面的所有word、excel、ppt、pdf文件重命名为文件内容的第一行。 我们有些朋友可能不会…

PHP基于B/S版 医院不良事件管理系统源码vscode+laravel8医院如何加强不良事件上报系统的管理 AEMS系统源码

PHP基于B/S版 医院不良事件管理系统源码vscodelaravel8医院如何加强不良事件上报系统的管理 AEMS系统源码 医院安全(不良)事件管理AEMS系统AEMS采用无责的、自愿的填报不良事件方式,有效地减轻医护人员的思想压力,实现以事件为主要…

数据分析从入门到精通 2.pandas修真之前戏基础

从爱上自己那天起,人生才真正开始 —— 24.5.6 为什么学习pandas numpy已经可以帮助我们进行数据的处理了,那么学习pandas的目的是什么呢? numpy能够帮助我们处理的是数值型的数据,当然在数据分析中除了数值型的数据还有好多其他类型…

笔试强训-day17_T2 十字爆破

一、题目链接 十字爆破 二、题目描述 牛牛在玩一个游戏: 一共有n行m列共nm个方格,每个方格中有一个整数。 牛牛选择一个方格,可以得到和这个方格同行、同列的所有数之和的得分。 例如:对于一个22的方格: 1 2 3 4 牛牛…

用js代码实现贪吃蛇小游戏

js已经学了大部分了,现在就利用我所学的js知识试试做贪吃蛇小游戏吧 以下部分相关图片以及思路笔记均出自渡一陈老师的视频 首先制作简单的静态页面,添加贪吃蛇移动的背景和相关图片,比如开始游戏等等 将各个功能均封装在函数中&#xff0…

大数据技术主要学什么,有哪些课程

大数据技术是指在海量数据的环境下,采集、存储、处理、分析和管理数据的一系列技术与方法。随着互联网、物联网以及各种智能设备的普及,数据量呈爆炸性增长,传统数据处理手段已难以应对,因此大数据技术应运而生,旨在从…

包管理工具npm、cnpm、yarn、NVM

[包]英文单词是package,代表了一组特定功能的源码集合 包管理工具: 管理[包]的应用软件,可以对[包]进行下载安装,更新,删除,上传等操作借助包管理工具,可以快速开发项目,提升开发效率 包管理工具是一个通用的概念,很多编程语言都有包管理工具,所以掌握好包管理工具非…

供应链|经典论文解读:(s,S) 策略在动态库存下的最优性

文章考虑了具有订购成本(由单位成本加上重新订购成本组成)的动态库存问题。具体而言,对于每个时期,系统在中期开始是做出一系列采购决策——这些采购有助于库存的积累,并在随后的周期被需求所消耗。每时期系统会产生各…

开源15T tokens!HuggingFace放出规模最大、质量最高预训练数据集 | 最新快讯

新智元报道 编辑:LRS FineWeb 是一个高质量的预训练数据集,包含 15T 个 tokens,主要包含英语文本;消融实验证明了 FineWeb 数据集的质量要高于其他开源数据集;数据清洗脚本也已开源。 Meta 最近开源的 Llama 3 模型再次…

如何根据IP获取国家省份城市名称PHP免费版

最近项目遇到需要根据IP获取用户国家功能需求,网上找了一下,很多API接口都需要付费,考虑为公司节约成本,就取找找有没有开源的 github 上面那个包含多种语言,下面这个只有php,用法很简单 $ip 114.114.114…

QT7_视频知识点笔记_1_ 基础知识(帮助文档),窗口(内存回收机制),信号槽(传参),Lambda表达式

1.QT基础 QT是一个框架,不用像C语言自己从底层写,需要的功能可以先看是否QT库中有直接可使用的 帮助文档的使用:F1跳入帮助文档, QT中常用的类:比如QPushbutton,查看帮助文档则可知道对应的函数和解决方…

C语言知识点补充——操作符详解

1、计算幂次数和平方根 使用<math.h>数学库 pow()函数计算幂次数&#xff1b;sqrt()函数计算平方根。 注&#xff1a;sqrt()输入同样的数字&#xff0c;计算出来的数值&#xff0c;可能不相等&#xff0c;因为输出double数&#xff0c;小数点后面的数值不一定一致。 2…

制作外贸脚本的流程和代码分享!

在全球化的今天&#xff0c;外贸业务成为了许多企业拓展市场、增加收入的重要途径&#xff0c;而在外贸业务中&#xff0c;一个优秀的脚本往往能够起到事半功倍的效果。 那么&#xff0c;如何制作一个高效、专业的外贸脚本呢?本文将为您详细解析制作外贸脚本的流程&#xff0…

力扣每日一题-拆炸弹-2024.5.5

力扣题目&#xff1a;拆炸弹 题目链接: 1652.拆炸弹 题目描述 代码思路 根据代码实现分为k等于0和k不等于0的情况。k等于0很容易处理&#xff0c;而k不等于0时&#xff0c;需要使用滑动窗口的方式来解决。先根据小于0或大于0确定一个窗口&#xff0c;然后移动&#xff0c;获…