Ruby n = 3233, e = 17, 明文是 65,密文根据公式得出 2790,但是如果明文是字符串,密文怎么算

ad583255925 · September 20, 2018 · Last by ad583255925 replied at September 21, 2018 · 1102 hits

对接的客户公司,给的公钥分为了 n 和 e

c = (65**17). modulo(3233) = 2790

c 就是密文

但是假设说我要加密的是字符串,我是把字符串转化为什么,用什么方法

RSA ?

转成数字编码啊

Reply to ad583255925
OpenSSL::PKey::RSA.new(private_key).private_encrypt(string)
Reply to lithium4010

private_key 我是没有的,这里一般是公钥,但是客户给我的公钥是两个数字,分别为 keyN 和 keyE

Reply to lithium4010

可是一个字符串,转换为数字码之后,是一个巨大的数组,这个怎么带进这个公式

Reply to ad583255925

字符串是不是用字符的 ASCII 码?

Reply to rocLv

http://aandds.com/blog/rsa-example.html 没错,然后把每个字符的 16 进制的码拼起来,不过 OpenSSl 库实际上已经帮忙全做掉了

key = OpenSSL::PKey::RSA.new(2048)
key.set_key(n, e, nil)
You need to Sign in before reply, if you don't have an account, please Sign up first.