urlsafe_base64(n=nil, padding=false)
Class Public methods
::urlsafe_base64 generates a random URL-safe base64 string.
The argument n specifies the length of the random length. The length of the result string is about 4/3 of n.
If n is not specified, 16 is assumed. It may be larger in future.
The boolean argument padding specifies the padding. If it is false or nil, padding is not generated. Otherwise padding is generated. By default, padding is not generated because â=â may be used as a URL delimiter.
The result may contain A-Z, a-z, 0-9, â-â and â_â. â=â is also used if padding is true.
p SecureRandom.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg" p SecureRandom.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg" p SecureRandom.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ==" p SecureRandom.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
If secure random number generator is not available, NotImplementedError is raised.
See RFC 3548 for the definition of URL-safe base64.
Please login to continue.