Data encrypted with openssl_public_encrypt is different every time?

前端 未结 1 1470
無奈伤痛
無奈伤痛 2021-01-13 17:34

why is the content of $encrypted every time different?

// aquire public key from server
$server_public_key = openssl_pkey_get_public(file_get_contents(\"C:\         


        
1条回答
  •  孤街浪徒
    2021-01-13 18:07

    The PKCS#1 encryption algorithm uses some random seed to make the cipher-text different every time.

    This protects the cipher-text against several attacks, like frequency analysis, ciphertext matching. For example, if you were using a public key to encrypt all your password without randomness. All the same password will yield the same cipher-text. Someone can figure out all the popular passwords by checking the frequency of the cipher-text.

    For symmetric key encryption, IV (Initial Vector) serves a similar purpose.

    0 讨论(0)
提交回复
热议问题