Hi all,
The following program creates an RSA key pair and prints
the length of its public key modulus. Eventhough I have
initialized its size as 1024(128 bytes), the printed length is
129. What is behind this behavoiur..?
public static void main(String args[]){
KeyPairGenerator kpg = null ;
try{
kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
}catch(Exception e){
e.printStackTrace();
}
KeyPair kp = kpg.genKeyPair();
RSAPublicKey puKey = (RSAPublicKey)kp.getPublic();
System.out.println("Key
Length:"+puKey.getModulus().toByteArray().length);
}
regards
Sijo
Roedy Green - 18 Aug 2003 22:35 GMT
> Eventhough I have
>initialized its size as 1024(128 bytes), the printed length is
>129. What is behind this behavoiur..?
is there simply a lead 0 byte? Perhaps it is there just to ensure the
number is treated as positive.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.