#ruby - 05 June 2019
« Back 1 day Forward 1 day »
[01:18:30] haxx0r: how to encrypt a file with a public key (and somewhere else decrypt with privatekey)? i can't find it
[01:21:46] haxx0r: we also upload a screenshot with sensitive data for the user, but 3 days after we want also to decrypt it
[01:23:13] havenwood: haxx0r: The JOSE gem has some good alg options: https://www.rubydoc.info/gems/jose/file/docs/EncryptionAlgorithms.md
[01:24:27] havenwood: haxx0r: Here's an example of a symmetric key wrap: https://gist.github.com/havenwood/e18de5fa23ec1c49e3feab493d579909
[01:36:21] havenwood: haxx0r: You can just put the bytes of the file in the payload, then encrypt them. You could Base64 them first, but you shouldn't have to.
[01:41:05] haxx0r: openssl enc -aes-256-cbc -salt -in SECRET_FILE -out SECRET_FILE.enc -pass file:./key.bin
[01:43:02] havenwood: haxx0r: here's a bit more advanced option: https://github.com/crypto-rb/rbnacl/wiki/Public-Key-Encryption
[01:45:48] haxx0r: but i go for decrypting it: openssl enc -d -aes-256-cbc -in test.txt -out test.ori.txt -pass file:./private.key
[01:46:36] havenwood: haxx0r: You can use OpenSSL in Ruby. Are you doing this from Ruby or is the command line or other languages fine as well?
[01:49:46] havenwood: RbNaCl is pretty nice. https://github.com/crypto-rb/rbnacl/blob/master/README.md
[12:15:55] KrzaQ: I'm on Windows, and TCPSocket.new seems to take a bit over 1 second to create a socket, consistently
[12:19:51] KrzaQ: hm, it seems that when I change 'localhost' to '127.0.0.1' it drops dramatically, to ~15-20ms
[13:17:20] IGnorAND: anyone try http://jsonapi-rb.org/ has_many :comments data seems to yield no attributes for the comments.
[14:39:23] phaul: imagine you have pascal_triangle(n). can you append stuff to it to extend it to be pascal_triangle(n+1) ?
[14:42:54] phaul: def pascal_triangle(n) ; if n == 1; then [] else prev=pascal_trianlge(n-1); prev + (extend_last_row(prev[-1]); end
[14:43:25] phaul: where extend_last_row just constructs the new row from the last row of the already existing smaller triangle
[15:42:31] Seance[m]: I'm not sure how the end condition of checking the palindrom is progressed by this piece of code
[15:42:50] Seance[m]: I see that string and [-1] check for the equality of the first and last character
[15:43:57] Seance[m]: does ruby check the relationship in the range and continue to loop through progressively?
[15:44:04] phaul: you are checking palindromeness on a string that is 2 chars shorter ( removed first and last ) so it progresses towards the empty string
[15:46:00] phaul: well it just keeps calling palindrome to decide if the next shorter string is palindrome. At some point it calls itself wit the empty string, which I assume handled in this function as well
[15:47:15] phaul: one has to be careful about the edge cases especially ending with 1 character string at the end.
[15:47:48] deathwishdave: In ruby, the following regexp [a-zA-Z]|(?<=')\s*(?=') matches "( 'one' , 'two','three' ,four, '')" correctly https://rubular.com/r/aCKyC6f4uXtQXd
[15:48:18] Seance[m]: Yeah, the empty string was handled in un snippeted parts, that was the only piece I didn't understand, and I didn't want to violate the code pasting length stuff
[15:48:47] deathwishdave: however, I am translating it to C++, which does not support look-around assertions:
[15:49:13] deathwishdave: is there an alternative regexp that does not use look-around assertions please?
[15:55:16] havenwood: deathwishdave: We could give you lots of solutions in Ruby, but you want C++, right?
[15:55:43] havenwood: deathwishdave: One option is boost::regex, but a C++ channel would probably be a better place to ask.
[20:18:52] VSpike: Why is it that .to_json will correctly descend into a class's attributes but .to_xml will not? https://bpaste.net/show/b77b99f9bc49
[20:30:42] havenwood: VSpike: They both attempt to, but #to_json was implemented and #to_xml was not on svc.
[21:55:04] nomercy: for example when it passes "PROT P" command, output is from previous one, "200 Command PBSZ okay" :D