Using colors in HTML, CSS and JavaScript is easy. However, it’s often necessary to programmatically generate colors, i.e. you need a color which is 20% brighter than #123 or 10% darker than #abcdef.
When you call getEncoded on an RSA private key, most providers will return the private key in PKCS #8 format. This is the case with your example.
CSS3 provides a great solution: HSL. Rather than using hex or RGB colors, you can set the Hue, Saturation, Luminosity (or Lightness) and, optionally, the opacity, e.g.
HSL and HSLA are supported in most browsers except IE8 and below. You can set the third luminosity parameter to change how bright or dark your color should be.
Unfortunately, we don’t always have the luxury of working in HSL. While you may be able to set an individual HSL color, the browser ultimately converts it to RGB. In addition, RGB is generally easier to use and you probably have colors already defined in that format.
There are various algorithms to change color luminosity. Many convert RGB to HSL then back again which is a fairly convoluted calculation for client-side scripting. Therefore, I’ve written a quick and simple cross-browser solution in JavaScript. ColorLuminance accepts two parameters:
The full code:
In essence, the first three lines clean the string and expand 3-digit hex codes to a full 6-digit representation.
The loop extracts the red, green and blue values in turn, converts them to decimal, applies the luminosity factor, and converts them back to hexadecimal. Windows 8.1 pro build 9600 key generator. Examples:
Please view the demonstration page; the color gradient is generating using a series of 100 div
elements with slightly lighter backgrounds.
I hope you find it useful. I’ll be using the function in another demonstration coming soon on SitePoint…
This class provides the functionality of a secret (symmetric) key generator.Key generators are constructed using one of the getInstance
class methods of this class.
KeyGenerator objects are reusable, i.e., after a key has been generated, the same KeyGenerator object can be re-used to generate further keys.
There are two ways to generate a key: in an algorithm-independent manner, and in an algorithm-specific manner. The only difference between the two is the initialization of the object:
All key generators share the concepts of a keysize and a source of randomness. There is an init
method in this KeyGenerator class that takes these two universally shared types of arguments. There is also one that takes just a keysize
argument, and uses the SecureRandom implementation of the highest-priority installed provider as the source of randomness (or a system-provided source of randomness if none of the installed providers supply a SecureRandom implementation), and one that takes just a source of randomness.
Since no other parameters are specified when you call the above algorithm-independent init
methods, it is up to the provider what to do about the algorithm-specific parameters (if any) to be associated with each of the keys.
For situations where a set of algorithm-specific parameters already exists, there are two init
methods that have an AlgorithmParameterSpec
argument. One also has a SecureRandom
argument, while the other uses the SecureRandom implementation of the highest-priority installed provider as the source of randomness (or a system-provided source of randomness if none of the installed providers supply a SecureRandom implementation).
In case the client does not explicitly initialize the KeyGenerator (via a call to an init
method), each provider must supply (and document) a default initialization.
Every implementation of the Java platform is required to support the following standard KeyGenerator
algorithms with the keysizes in parentheses: