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

請問關於加密的問題 #139

Open
Sikhye opened this issue Oct 26, 2016 · 2 comments
Open

請問關於加密的問題 #139

Sikhye opened this issue Oct 26, 2016 · 2 comments

Comments

@Sikhye
Copy link

Sikhye commented Oct 26, 2016

我有以下幾行 Java 程式碼需要移植到 Ruby 來,但是找不到相對應的函式可以用,不知道是否有人可以指導如何轉換成 Ruby 程式碼,謝謝。

byte[] seed = Base64.getDecoder().decode((byte[])"aGVsbG93b3JsZA==".getBytes("UTF-8"));
byte[] key = new byte[16];

SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG");
rnd.setSeed(seed);
rnd.nextBytes(key);
@GeorgioWan
Copy link

Hello,

  1. 從 ruby-doc 中可以找到 base64SecureRandom 的用法。
  2. SHA1 的話可以試試 digest:
require 'digest/sha1'
p Digest::SHA1.hexdigest('testtest')

以上是我曾經用過的方式,你再試試看!!

@Sikhye
Copy link
Author

Sikhye commented Oct 26, 2016

@GeorgioWan 謝謝回覆

目前比較大的困擾是在 Java 程式中使用的 setSeed 方法,Java 內 setSeed 的參數可以是 byte[]long 的格式,而我現在只有看到 Ruby 的 Random 也可以設定 PRNG,但只支援 Integer

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