I have tried to implement a Drupal compatible authentication in Go and use this package for base64 encoding: golang.org/src/encoding/base64/base64.go
The Result: the created and in Drupal saved hashes don't matches. Only after reimplementing Go's base64-package, where I do the bit shifting like in Drupals base64Encode() the hashes matched:
input bit location: abcdefgh ijklmnop qrstuvwx
Go's base64.go bit location: ..abcdef ..ghijkl ..mnopqr ..stuvwx
PHP's base64Encode() bit location: ..cdefgh ..mnopab ..wxijkl ..qrstuv
Well, I do instead of Google's implementation:
...
for si < n {
// Convert 3x 8bit source bytes into 4 bytes
val := uint(src[si+0])<<16 | uint(src[si+1])<<8 | uint(src[si+2])
dst[di+0] = enc.encode[val>>18&0x3F]
dst[di+1] = enc.encode[val>>12&0x3F]
dst[di+2] = enc.encode[val>>6&0x3F]
dst[di+3] = enc.encode[val&0x3F]
si += 3
di += 4
}
...
my own implementation now with behalf of Drupal's base64Encode()
...
for si < n {
// Convert 3x 8bit source bytes into 4 bytes
// val := uint(src[si+0])<<16 | uint(src[si+1])<<8 | uint(src[si+2])
val := uint(src[si+0]) | uint(src[si+1])<<8 | uint(src[si+2])<<16
dst[di+0] = enc.encode[val&0x3F]
dst[di+1] = enc.encode[val>>6&0x3F]
dst[di+2] = enc.encode[val>>12&0x3F]
dst[di+3] = enc.encode[val>>18&0x3F]
si += 3
di += 4
}
...
My Questions:
- is already there in Go an implementation like I did (reimplemented Drupal's base64Encode())?
- does this special base64 encoding have a name? Are there Literature/Publication references?