最近弄API,要用的RSA与Java通信,发现Ruby
但为什么会这样呢?Ruby不会无故的这么做,原来Ruby的Base64.encode64方法是遵循[url=https://tools.ietf.org/html/rfc2045#section-6.8]RFC 2045[/url]的规范,而后面的是遵循[url=https://tools.ietf.org/html/rfc4648#section-3.3]RFC 4648[/url]规范,也正如此,Ruby 1.9.1对Base64添加了
Edit:
同样的问题参见
[url]http://stackoverflow.com/questions/13301708/base64-encode-length-parameter[/url]
Base64.encode64(public_key#encrypt)
得到的值用Java不能decrypt,因为对RSA了解的不够深,不知道问题出在哪一方,经过一番周折,发现问题还是出在了Ruby的Base64.encode64方法上,该方法会将encoded的字符串每60个字符换行("\n"),把产生的换行去掉后就可以让Java正确decrypt了。
但为什么会这样呢?Ruby不会无故的这么做,原来Ruby的Base64.encode64方法是遵循[url=https://tools.ietf.org/html/rfc2045#section-6.8]RFC 2045[/url]的规范,而后面的是遵循[url=https://tools.ietf.org/html/rfc4648#section-3.3]RFC 4648[/url]规范,也正如此,Ruby 1.9.1对Base64添加了
#strict_encode64
和
#strict_decode64
,对于1.9.1以前的版本,Rails也提供了ActiveSupport::Base64.encode64s方法
Edit:
同样的问题参见
[url]http://stackoverflow.com/questions/13301708/base64-encode-length-parameter[/url]