Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

result length of encrypt here is twice than which in Java #1

Open
JeremeLau opened this issue Dec 3, 2018 · 9 comments
Open

result length of encrypt here is twice than which in Java #1

JeremeLau opened this issue Dec 3, 2018 · 9 comments

Comments

@JeremeLau
Copy link

Hi,bro,
I've met a strange issue, result length of encrypt here is twice than which in Java,
but backend can decrypt it correctly,
however, when I decrypt a LONG source string, backend denied the request.
So, I wonder why the twice

Plus : mode in Java
public static final String SIGN_TYPE_RSA = "RSA/ECB/PKCS1Padding";

@lsqswl
Copy link
Owner

lsqswl commented Dec 3, 2018

however, when I decrypt a LONG source string, backend denied the request.

I'm sorry I cann't understand what mean this sentence. Is java encrypt string and the js decrypt ?
The method is only used to encrypt-decrypt or decrypt-encrypt. That's no business of the request.

@JeremeLau
Copy link
Author

I mean why the encrypt result string is just the twice than what encrypted from Java platform using exactly rsa
And in that case, the twice result string can be decrypted by back-end though.
But, when the source string is too long , the TWICE long encrypted result string will be denied

@lsqswl
Copy link
Owner

lsqswl commented Dec 3, 2018

Can you give me a case with too long string which cannot be decrypt by java ? I try it frist. Thanks!

@JeremeLau
Copy link
Author

呃,中国人啊,讲中文吧
您没明白我的意思,老哥
我的意思是说,我用这个js的方法,加密出来的字符串,比我用java方法转出来的刚好长一倍,我想知道为什么会长一倍。但是,虽然长了一倍,但是还是可以被我们的后端解出来(后端是c)。
现在的问题是,我要把加密的字符串发送到后台,但是超过了后台最大能接收的字符长度。
因为后端不会改,他们的理由是java的能过,你不能过,就是你的问题,所以我只能在前端想办法。
您的这个方法本身没有问题,我只是想知道长度不一样的原因,

@lsqswl
Copy link
Owner

lsqswl commented Dec 3, 2018

我测试了一下我自己demo里面的那个字符串:
java: 344
object-c: 512
js:512

并非你说的2倍。

另: 我不明白你们服务端为啥会限制这个长度,基于什么原理限制长度。如果你们要开发ios端的,那肯定也不行,到时候怎么处理?

@JeremeLau
Copy link
Author

JeremeLau commented Dec 3, 2018

我试了很多次,确实是两倍

至于后台为什么限制,我管不了的事

我只是想知道为啥不一样长度还能解出来

我想知道原理

@lsqswl
Copy link
Owner

lsqswl commented Dec 3, 2018

rsa算法里面,长度很长的字符串进行加密,是分段进行的,长度不足以空格或者其他特殊方式补齐。分段补齐的策略不同,长度就不同。

@JeremeLau
Copy link
Author

老哥,非常抱歉上面说了两倍的说法
我今天用iOS的和Android的试了下长字符串加密,iOS和Android的长度是一样的,但是js的就长很多,并且原加密字符串长度越长,相差的越大(不是上文说的两倍)

@lsqswl
Copy link
Owner

lsqswl commented Dec 7, 2018

本库是基于jsencrypt的封装,该库只支持短数据加解密。你这要求应该只有去修改jsencrypt才能满足要求。只能看下他的加密补齐方式。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants