Diffie Hellman密鑰交換

In short, the Diffie Hellman is a widely used technique for securely sending a symmetric encryption key to another party. Before proceeding, let’s discuss why we’d want to use something like the Diffie Hellman in the first place. When transmitting data over the Internet as plain text, it’s easy for someone to use some kind of packet sniffer like WireShark to capture packets. A malicious person, could listen in on the conversation you had with your girlfriend or worse yet, steals passwords and credit card information. Fortunately, some very smart people came up with a way to encode information for transit. The process by which we convert ordinary plain text into something unintelligible and vice-versa is known as cryptography. The most basic example of cryptography is called the Caesar Cypher.

簡而言之,Diffie Hellman是一種用于將對稱加密密鑰安全發送給另一方的廣泛使用的技術。 在繼續之前,讓我們討論為什么首先要使用Diffie Hellman之類的東西。 當以純文本格式在Internet上傳輸數據時,對于某人來說,使用諸如WireShark之??類的數據包嗅探器來捕獲數據包很容易。 惡意軟件的人可能會收聽您與女友的交談,甚至更糟,他們會竊取密碼和信用卡信息。 幸運的是,一些非常聰明的人想出了一種方法來編碼信息以進行運輸。 我們將普通的純文本轉換為難以理解的過程的過程,反之亦然,即密碼術 。 密碼學的最基本示例稱為凱撒密碼。

Image for post
https://commons.wikimedia.org/wiki/File:Caesar_Shift_Cipher_Wheel.pnghttps://commons.wikimedia.org/wiki/File:Caesar_Shift_Cipher_Wheel.png

In essence, both parties have a symmetric key which specifies what characters map to what symbol of the encrypted text. Those who don’t possess the key cannot read the message. For example, in the preceding image, the character ‘A’ would be encoded as a ‘T’ in the encrypted message. An individual on the receiving end could then use the same Caesar Cypther to decode the message.

本質上,雙方都有一個對稱密鑰,它指定哪些字符映射到加密文本的什么符號。 那些沒有鑰匙的人無法閱讀消息。 例如,在前面的圖像中,字符“ A”在加密消息中將被編碼為“ T”。 然后,接收端的個人可以使用相同的Caesar Cypther對消息進行解碼。

In the realm of computer networking, the problem with symmetric encryption algorithms is that the key must be inevitably be sent over the network to the other party so that they can decrypt incoming messages, and encrypt them in turn. If a malicious actor happened to be listening to the network at that point in time, they could obtain the key, and use it for nefarious purposes.

在計算機網絡領域,對稱加密算法的問題在于必須將密鑰不可避免地通過網絡發送給另一方,以便他們可以解密傳入的消息并依次對其進行加密。 如果惡意行為者恰好在該時間點正在偵聽網絡,則他們可以獲得密鑰,并將其用于惡意目的。

This is where asymmetrical encryption comes in to play. Asymmetrical encryption works by generating a public and private key pair. The public key can only be used to encrypt messages whereas the private key can only be used to decrypt messages. For example, when you do your online banking, you give the bank your public key which is then used to encrypt the data sent back to you. If a bad guy gets their hands on the public key, they can’t do any real harm since they only have the ability to encrypt data.

這就是非對稱加密發揮作用的地方。 非對稱加密通過生成公鑰和私鑰對來工作。 公鑰只能用于加密消息,而私鑰只能用于解密消息。 例如,當您進行在線銀行業務時,您給銀行您的公共密鑰,然后將其用于加密發送回給您的數據。 如果一個壞人得到了公鑰,那么他們就不會造成任何真正的傷害,因為他們只能加密數據。

Today, the most widely used asymmetrical encryption algorithm is RSA. RSA stands for Rivest–Shamir–Adleman after the people who first described the algorithm back in 1977. The RSA algorithm encrypts messages by raising the message to the power of the public key and then taking the modulo of the result. To decrypt a given message, we raise it to the power of the private key and then take the modulo of the result. RSA relies on a mathematical concept known as a one-way function. Suppose we had the following equation:

如今,使用最廣泛的非對稱加密算法是RSA。 在此之后,RSA代表Rivest–Shamir–Adleman 最早是在1977年對算法進行描述的人們。RSA算法通過將消息提升為公鑰的能力然后對結果取模來對消息進行加密。 為了解密給定的消息,我們將其提升為私鑰的能力,然后對結果取模。 RSA依賴于稱為單向函數的數學概念。 假設我們有以下等式:

Image for post

Now, say you were given the number 8 and asked to get back to 23. Could you do it?

現在,假設您得到的數字為8,并要求返回23 。 你能做到嗎?

Image for post
Image for post

It’s relatively easy to work our way backwards in order figure out all the factors of 8.

找出8的所有因素,倒退比較容易。

In contrast, the modulo (synonymous with remainder) operation is an example of a one-way function. Suppose we had the following equation:

相反,取模(與余數同義)操作是單向函數的一個示例。 假設我們有以下等式:

Image for post

If you were asked to derive 11 from 3, could you do it?

如果要求您從3導出11 ,您可以這樣做嗎?

Image for post

You may be able to obtain the correct answer (11) by trying out all the different possibilities (i.e. 3 % 4 = 3, 7 % 4 = 3, 11 % 4 = 3), but when the numerator is very large, as in the case of RSA (i.e. 4096 bits long), there are a lot and I mean A LOT of permutations that give a remainder of 3. Given this property, hackers would have no choice but to use brute force (try every possibility) to determine the private key from the encrypted message and public key. Given that today’s keys are 4096 bits long, it would take traditional computers centuries to go through all the possible values.

通過嘗試所有不同的可能性(例如3%4 = 3,7%4 = 3,11%4 = 3) ,您可能能夠獲得正確的答案( 11 ) ,但是當分子很大時,例如對于RSA(即4096位長)的情況,有很多,我的意思是說,很多置換提供剩余的3。給定此屬性,黑客別無選擇,只能使用蠻力(嘗試各種可能性)來確定加密消息中的私鑰和公鑰。 鑒于今天的密鑰長為4096位,傳統計算機要花所有幾個世紀才能經歷所有可能的值。

In practice, asymmetrical encryption is 3 to 5 orders of magnitude slower than symmetric encryption. Therefore, we don’t encrypt the actual payload using asymmetrical encryption. Rather, we use a technique like Diffie-Hellman to securely send a symmetric encryption key to the other party, and then use said key to encrypt/decrypt all further messages.

實際上,非對稱加密比對稱加密慢3至5個數量級。 因此,我們不會使用非對稱加密來加密實際的有效負載。 相反,我們使用Diffie-Hellman之類的技術將對稱加密密鑰安全地發送給另一方,然后使用所述密鑰對所有其他消息進行加密/解密。

模算術(RSA)Diffie Hellman (Modulo Arithmetic (RSA) Diffie Hellman)

We’ve already described the RSA at a high level. Now, let’s take a look at a concrete example. Suppose, Bob wants to send a message to Alice. Bob will start off by generating a new random prime number N and corresponding generator g.

我們已經在較高層次上描述了RSA。 現在,讓我們看一個具體的例子。 假設,鮑勃想要發送一條消息給愛麗絲。 Bob將通過生成一個新的隨機素數N和相應的生成器g來開始。

NOTE: g isn’t random, but how we go about selecting it is beyond the scope of this article.

注意:g不是隨機的,但是如何選擇它超出了本文的范圍。

In practice, N is a large number. However, for the sake of simplicity, we’ll use the following values:

實際上,N是一個很大的數字。 但是,為簡單起見,我們將使用以下值:

Image for post
Image for post

Both g & N are sent over the network as plain text. Bob then generates a secret key a = 2. Next, Bob raises the generator g to the power of his secret key a, and takes the modulo of the result. The end product A = 5 is sent to Alice.

g和N均以純文本形式通過網絡發送。 鮑勃然后生成一個秘密密鑰a = 2 。 接下來,鮑勃將生成器g提升到他的私鑰a的冪,并對結果取模。 最終產品A = 5被發送給Alice。

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

On the other end, Alice performs the same steps — that is, she generates a secret key b, raises the generator g to the power of her secret key b, takes the modulo of the product, and sends the end result B = 3 to Bob.

在另一端,愛麗絲執行相同的步驟-即,她生成一個秘密密鑰b,將生成器g提升為她的秘密密鑰b的冪,取乘積的模,然后將最終結果B = 3發送給鮑勃

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Even if a malicious actor were to snoop on their traffic. They wouldn’t be able to derive Bob’s or Alice’s secret key from A and B.

即使惡意行為者會監聽他們的流量。 他們將無法從A和B導出Bob或Alice的秘密密鑰。

Upon receiving B from Alice, Bob raises it to the power of his private key a, and takes the modulo of the result.

一旦從接收到 愛麗絲(Alice),鮑勃(Bob)將其提升為私鑰a的冪,然后對結果取模。

Image for post
Image for post
Image for post
Image for post
Image for post

Alice does the same.

愛麗絲也一樣。

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Alice and Bob both end up with the same number, 9, in this case. They then use 9 as the key for a symmetrical encryption algorithm like AES.

在這種情況下,愛麗絲和鮑伯都以相同的數字9結束。 然后,他們使用9作為對稱加密算法(例如AES)的密鑰。

橢圓曲線Diffie Hellman (Elliptic Curve Diffie Hellman)

Trying to derive the private key from a point on an elliptic curve is harder problem to crack than traditional RSA (modulo arithmetic). In consequence, Elliptic Curve Diffie Hellman can achieve a comparable level of security with less bits.

試圖從橢圓曲線上的某個點導出私鑰比傳統的RSA(模算術)更難破解。 因此,橢圓曲線Diffie Hellman可以用更少的位達到可比較的安全級別。

A smaller key requires less computational steps in order to encrypt/decrypt a given payload. You wouldn’t notice much of a difference when establishing secured connections from your local machine. However, on something like a Medium web server that performs thousands upon thousands of key exchanges every second, the use of Elliptic Curve Diffie Hellman can lead to significant savings.

較小的密鑰需要較少的計算步驟才能加密/解密給定的有效負載。 從本地計算機建立安全連接時,您不會注意到很大的不同。 但是,在諸如中型Web服務器這樣每秒執行成千上萬次密鑰交換的事物上,使用橢圓曲線Diffie Hellman可以節省大量資金。

We can visualize the domain of all possible numbers in a Diffie Hellman RSA key exchange as a circle (due to the nature of the modulo function). The larger the value of n, the larger the circle, and the harder it is to guess the correct number.

我們可以將Diffie Hellman RSA密鑰交換中所有可能數字的域可視化為一個圓(由于取模函數的性質)。 n的值越大,圓圈越大,猜測正確的數字就越困難。

Image for post

In contrast, as the name implies, the domain of all possible numbers for an elliptic curve Diffie Hellman key exchange takes the form of an elliptic curve.

相反,顧名思義,橢圓曲線的所有可能數字的域Diffie Hellman密鑰交換采用橢圓曲線的形式。

Image for post

The preceding elliptic curve is characterized by the following mathematical equation:

前面的橢圓曲線的特征在于以下數學方程式:

Image for post

In the wild, it’s pretty common to take use the equation (mod n).

在野外,使用等式( mod n )很常見。

Image for post

In practice, you want to use curves that have been developed by professional mathematicians, and vetted to ensure they are secure.

在實踐中,您想使用由專業數學家開發并經過審查以確保其安全性的曲線。

Instead of raising things to powers as in the case of RSA, elliptic curve Diffie Hellman works by adding the point G to itself several times over.

橢圓曲線Diffie Hellman并沒有像RSA那樣提高功效,而是通過將G點自身加數倍來工作。

Let’s take a look at an example. Suppose Bob initiates a connection with Alice. Bob selects a generator G (a point on the curve) and the parameters a, b, n of the elliptic curve equation, and sends them across the wire as plain text.

讓我們看一個例子。 假設Bob啟動與Alice的連接。 鮑勃選擇一個生成器G(曲線上的一個點)和橢圓曲線方程的參數abn ,并將它們以純文本形式發送到網上。

Image for post
Image for post

Bob and Alice then each generate a private key (number). For the sake of simplicity, let’s assume Bob selects b = 9 and Alice selects a = 3. Bob and Alice are responsible for computing bG = 9G and aG = 3G respectively.

然后,Bob和Alice各自生成一個私鑰(數字)。 為了簡單起見,我們假設Bob選擇b = 9并選擇 愛麗絲選擇a = 3 。 Bob和Alice分別負責計算bG = 9GaG = 3G

In order to compute xG (where x is any number), we use the formulas for adding and doubling a point. For instance, to determine 2G, we use the formula for doubling a point.

為了計算xG (其中x是任意數字) 我們使用公式對一個點進行加法和加倍。 例如,要確定2G,我們使用公式將點加倍。

Image for post
Image for post
Image for post

To take the modulo of a fraction, we can make use of a modular multiplicative inverse calculator.

為了取小數的模,我們可以使用模塊化的乘法逆計算器。

We then multiply the answer with 77 % 17 = 9, and take the modulo of the result.

然后,將答案乘以77%17 = 9,并對結果取模。

Image for post
Image for post
Image for post

The x coordinate of the point can be calculated as follows:

點的x坐標可以如下計算:

Image for post
Image for post
Image for post
Image for post

We then use x2G to compute y2G.

然后,我們使用x2G計算y2G。

Image for post
Image for post
Image for post
Image for post
Image for post

To calculate 3G, we use the formula for adding a point.

為了計算3G,我們使用公式來添加一個點。

Image for post

We start off by calculating the slope.

我們從計算斜率開始。

Image for post
Image for post
Image for post

Then we compute the x position of the new point.

然后,我們計算新點的x位置。

Image for post
Image for post
Image for post

Finally, we use the value of the x coordinate to compute y.

最后,我們使用x坐標的值來計算y。

Image for post
Image for post
Image for post
Image for post

Bob sends bG = 9G = (7, 6) over the network. Similarly, Alice sends aG = 3G = (10, 6). In the event, a malicious actor is listening, it’s damn well impossible to derive the value of aG or bG from the points (7, 6) and (10, 6) on the elliptic curve.

鮑勃通過網絡發送bG = 9G =( 7,6 ) 。 類似地,愛麗絲發送aG = 3G =(10,6) 。 如果出現惡意行為者正在監聽的情況,從橢圓曲線上的點( 7,6 )( 10,6)得出aGbG的值是絕對不可能的。

Image for post

Once Bob receives aG = (10 , 6) from Alice, he computes abG = 9(3G) = 27G = (13, 7). When Alice receives bG = (7, 6) from Bob, she computes abG = 3(9G) = 27G = (13, 7). They then both use the x coordinate of abG as their symmetrical encryption key for all further data transfer.

一旦Bob從Alice 收到aG =(10,6 ) ,他就計算abG = 9(3G)= 27G =(13,7) 。 當Alice從Bob收到bG =( 7,6 )時,她計算abG = 3(9G)= 27G =(13,7) 。 然后,它們都將abG的x坐標用作所有進一步數據傳輸的對稱加密密鑰。

翻譯自: https://towardsdatascience.com/diffie-hellman-key-exchange-f673d617137

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391327.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391327.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391327.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

高效能程序猿的修煉

下載地址:http://download.csdn.net/detail/xiaole0313/8931785 高效能程序猿的修煉 《高效能程序猿的修煉是人民郵電出版社出版的圖書。本書是coding horror博客中精華文章的集合。全書分為12章。涉及邁入職業門檻、高效能編程、應聘和招聘、團隊協作、高效工作環境…

Spring 中的 LocalSessionFactoryBean和LocalContainerEntityManagerFactoryBean

Spring和Hibernate整合的時候我們經常會有如下的配置代碼 1&#xff0c;非JPA支持的配置 <!-- 配置 Hibernate 的 SessionFactory 實例: 通過 Spring 提供的 LocalSessionFactoryBean 進行配置 --> <!-- FacotryBean 配置的時候返回的不是本身而是返回的FactoryBean 的…

如何通過建造餐廳來了解Scala差異

I understand that type variance is not fundamental to writing Scala code. Its been more or less a year since Ive been using Scala for my day-to-day job, and honestly, Ive never had to worry much about it. 我了解類型差異并不是編寫Scala代碼的基礎。 自從我在日…

linux的/etc/passwd、/etc/shadow、/etc/group和/etc/gshadow

1./etc/passwd 存儲用戶信息 [rootoldboy ~]# head /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin 一行記錄對應著一個用戶&#xff0c;每行記錄被冒號:分隔為7個字段&#xff0c;這7個字段的具體含…

組織在召喚:如何免費獲取一個js.org的二級域名

之前我是使用wangduanduan.github.io作為我的博客地址&#xff0c;后來覺得麻煩&#xff0c;有把博客關了。最近有想去折騰折騰。先看效果&#xff1a;wdd.js.org 如果你不了解js.org可以看看我的這篇文章:一個值得所有前端開發者關注的網站js.org 前提 已經有了github pages的…

linkedin爬蟲_您應該在LinkedIn上關注的8個人

linkedin爬蟲Finding great mentors are hard to come by these days. With so much information and so many opinions flooding the internet, finding an authority in a specific field can be quite tough.這些天很難找到優秀的導師。 互聯網上充斥著如此眾多的信息和眾多…

重學TCP協議(4) 三次握手

1. 三次握手 請求端&#xff08;通常稱為客戶&#xff09;發送一個 S Y N段指明客戶打算連接的服務器的端口&#xff0c;以及初始序號。這個S Y N段為報文段1。服務器發回包含服務器的初始序號的 S Y N報文段&#xff08;報文段2&#xff09;作為應答。同時&#xff0c;將確認序…

[設計模式]State模式

《Java與模式》 又稱狀態對象模式。狀態模式是對象的行為模式。GOF95 一個對象的行為取決于一個或者多個動態變化的屬性&#xff0c;這樣的屬性叫做狀態。這樣的對象叫做有狀態的對象&#xff08;stateful&#xff09;。 狀態模式把一個所研究的對象的行為包裝在不同的狀態對象…

java溫故筆記(二)java的數組HashMap、ConcurrentHashMap、ArrayList、LinkedList

為什么80%的碼農都做不了架構師&#xff1f;>>> HashMap 摘要 HashMap是Java程序員使用頻率最高的用于映射(鍵值對)處理的數據類型。隨著JDK&#xff08;Java Developmet Kit&#xff09;版本的更新&#xff0c;JDK1.8對HashMap底層的實現進行了優化&#xff0c;例…

前置交換機數據交換_我們的數據科學交換所

前置交換機數據交換The DNC Data Science team builds and manages dozens of models that support a broad range of campaign activities. Campaigns rely on these model scores to optimize contactability, volunteer recruitment, get-out-the-vote, and many other piec…

aws 彈性三劍客_AWS和彈性:超越用戶需求

aws 彈性三劍客I’ll assume that, one way or another, you’re already familiar with many of AWS’s core deployment services. That means you now know about:我假設您已經熟悉許多AWS的核心部署服務。 這意味著您現在知道&#xff1a; ? EC2 instances and AMIs (Ama…

leetcode 368. 最大整除子集(dp)

給你一個由 無重復 正整數組成的集合 nums &#xff0c;請你找出并返回其中最大的整除子集 answer &#xff0c;子集中每一元素對 (answer[i], answer[j]) 都應當滿足&#xff1a; answer[i] % answer[j] 0 &#xff0c;或 answer[j] % answer[i] 0 如果存在多個有效解子集&a…

在Centos中安裝mysql

下載mysql這里是通過安裝Yum源rpm包的方式安裝,所以第一步是先下載rpm包 1.打開Mysql官網 https://www.mysql.com/, 點擊如圖選中的按鈕 點擊如圖框選的按鈕 把頁面拉倒最下面,選擇對應版本下載,博主這里用的是CentOS7 下載完成后上傳到服務器,由于是yum源的安裝包,所以…

碩士可以跟別的導師做實驗嗎_如何成為一名導師可以成為雙刃劍

碩士可以跟別的導師做實驗嗎Mentoring is the ability to give advise or train someone, often times, who is less knowledgeable in a particular field. This is pretty much common place in tech companies. There you usually have senior developers who, besides bein…

linux中權限對文件和目錄的意義

1.權限對文件的意義&#xff1a; 讀&#xff1a;可查看文件的內容 寫&#xff1a;可修改文件的內容&#xff08;但不能刪除文件&#xff09; 執行&#xff1a;可執行文件 2.權限對目錄的意義&#xff1a; 讀&#xff1a;可以查看目錄下的內容&#xff0c;即可以讀取該目錄下的結…

Docker 入門(1)虛擬化和容器

1 虛擬化 虛擬化是為一些組件&#xff08;例如虛擬應用、服務器、存儲和網絡&#xff09;創建基于軟件的&#xff08;或虛擬&#xff09;表現形式的過程。它是降低所有規模企業的 IT 開銷&#xff0c;同時提高其效率和敏捷性的最有效方式。 1.1 虛擬化用于程序跨平臺兼容 要…

量子相干與量子糾纏_量子分類

量子相干與量子糾纏My goal here was to build a quantum deep neural network for classification tasks, but all the effort involved in calculating errors, updating weights, training a model, and so forth turned out to be completely unnecessary. The above circu…

三角函數式的化簡

前言 為什么需要化簡三角函數式&#xff1f; 一、什么是三角函數式的化簡&#xff1f; 二、三角函數式的化簡標準是什么&#xff1f; 三、三角函數式化簡可能用到的變形&#xff1a; 弦切互化&#xff0c;1的代換&#xff0c;通分約分&#xff0c;配方展開&#xff0c;提取公因…

Python -- xlrd,xlwt,xlutils 讀寫同一個Excel

最近開始學習python,想做做簡單的自動化測試&#xff0c;需要讀寫excel,然后就找到了xlrd來讀取Excel文件&#xff0c;使用xlwt來生成Excel文件&#xff08;可以控制Excel中單元格的格式&#xff09;&#xff0c;需要注意的是&#xff0c;用xlrd讀取excel是不能對其進行操作的&…

計算機工程師分級_這些是每個計算機工程師都應該知道的數字

計算機工程師分級In 2010, Jeff Dean from Google gave a wonderful talk at Stanford that made him quite famous. In it, he discussed a few numbers that are relevant to computing systems. Then Peter Norvig published those numbers for the first time on the inter…