cryptography - trouble with {base64 encoding of sha256 result} password generator -
i'd encode sha-256 output (in hex) give me 16 character base64 string password using purposes. base64 appears not think should be. here's want.
(0) "00000000000000000000000000000000" -> "aaaaaaaaaaaaaaaa" (64) "00000000000000000000000000000040" -> "aaaaaaaaaaaaaaba" (255) "000000000000000000000000000000ff" -> "aaaaaaaaaaaaaac/" (2^16+16) "0000000000000000000000000000100f" -> "aaaaaaaaaaaaapap"
heres
base64encode("00000000000000000000000000000000") "mdawmdawmdawmdawmdawmdawmdawmdawmdawmdawmdaa"
this result consistent online converters, using r, etc., base64 not think , i'm trying else. if i'm not trying "encode in base 64", trying do?
my favorite is:
> base64encode(64) [1] "aaaaaaaauea=" > base64encode("64") [1] "njqa"
which baffles me
base64 works on byte arrays, in example, base64encode("00000000000000000000000000000000")
encoding string value "000...", byte array. since byte value character "0" 0x30, you're encoding byte array consisting of 32 0x30
bytes (and looks of it, null terminator (0x00) @ end).
if you're trying 16 character output, need encode 12 byte input (since base64 produces 4 characters of output 3 bytes of input), e.g. (you don't give language, i'm guessing @ syntax byte arrays { 0x.., 0x.., ... }
):
base64encode({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) = "aaaaaaaaaaaaaaaa" base64encode({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}) = "aaaaaaaaaaaaaaab" base64encode({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40}) = "aaaaaaaaaaaaaaba" etc...
the sha-xxx algorithms should naturally produce byte-array output, should able take appropriate number of bytes it, , pass them base64encode
. if sha method produces hex string output, you'll need convert hex string byte array before passing base64 encoding.
Comments
Post a Comment