porting java public key pdf

32
Porting Java Public Key Hash to C# .Net By Shaheryar Chaudhry ([email protected])

Upload: socknow

Post on 29-Dec-2015

30 views

Category:

Documents


0 download

DESCRIPTION

Java

TRANSCRIPT

Page 1: Porting Java Public Key PDF

Porting Java Public Key Hash to C# .Net �

By Shaheryar Chaudhry ([email protected])

Page 2: Porting Java Public Key PDF

Table of Contents �

��������

���� �������������� �� �

�����������������

���� ������� �� ������������

���� �������� ��������� ������ �� !

� ���� �������� ��������� � � �� "�� ���#��$��������# ���%

� � �� �����������&

! '�� #������������ ��������

���� ������ ������ ���(�����$)�� �������� �����!

(���*������� ������+,-!

� ������ ���(���+,-����� ������#��$�.���/

���� ���!��*��� ������� ������������� #� ������������ ��(��0

�� � �� "�� �� 0

� *��� ������0

� '�� #� �������� ������� 1

���������

*�#��������1

�������������&

Page 3: Porting Java Public Key PDF

���� �������������� ���

���� ��������������)�� ��������������2�3��&&!�

Abstract

4����� ��)����)�������#�5������� ���� �����) ���#�$����� $���� $)������������������

����� ������� ����� ��������6������������3�5����������������6���$���#��$� �� ������

���3� ���� ��$�� �����6�� ���� �7)���� �� ��#�5���� ��$)���� ��� � �� � ��� #��� ��$�����

���� ��������)��#�����$�����)8��8���������� 9�������������� ������6�������))� ��� ���

����� ������� ����� ���������) ���������)���#��$��))� ��� ������������������� ��� ����

� ��)�����$�5� �����������������������������$�����#�������)�����

4� ������$���� ������##�������������$�������)�����$��#������������������)����5���

5�������� �������������������)���#��$�����5���������� #�� ������������3��� ���)�)�����

)��� �86���� � ����� ��������6��5�����*���

����� ���5 �����.����)�����$���� ������������5�����������������6���3�� ���������� #��

���� ����� �� ��� ���� ���������� 6���� ����� ��� ����6 ��� ��5�� ���� #���� ���� �#� ����

�))� ��� ����������� �5 �������# ���� �7���� ���������� (�7�3�������$����� ��������

��5�����7)��������)��� ��6��3��������������.���3���������������������(���#��$�5��6�

������ #����������� �(����))� ��� ����: �����3��� ������$����� ����������5���������

�������� ������ �� (���;�� ���2<=��������������.����)�����$�������� #�����������

�� ����� ������ ������������������#���������$���3�� ##��������# � � �����#����$������

�����)��� ��������9� )�������� ���������5����

Page 4: Porting Java Public Key PDF

���� �������������� ���

����� ��������������)�� ��������������2�3��&&!�

Section 1: Introduction

1 Who should read?

4���$� �� �������� ����� ������� ������������������� �� ���������� ��.�������������

��� #� ��� �� ��(����� ���2<�>�5����3���������5������� ������������������������ ���

����� �� ���?���� #� �������������� ���.����2��)�����)� �����@�������������������

����������� ������� ���4� ������� �������$���������������6��5����5�������������5� ���

��� ��.����?�2<�(����))� ��� ����

A�#���� �� ������������� ������� ��3� �� ��� ���������$$���������������������������

��� ��6��5�������#����$��#���2��)�����)������������ ���)��6�������# ���� ��.����

���� (���#��$�5��6�:��� ������������������������# � � �����#����$�� �� )��� ���� ��

��������������������#���������� ���B���� #�����6��5��������$��C������������������$�

�����#����������$�$����

Page 5: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

����� ��������������)�� ��������������2�3��&&!�

Section 2: Signing the Data

4���" )�# ��� ������������������������ ��� 4� ��

.���� ������ �� ���)��� ���� #��� � �� ��� ���� ����� ����

��� #� ��� ���� ����� �� ��� )� ����� ���� )��� �� 6����

���)��� ���������������������������+,-����� ��6���#���

(��� #��$�5��6� 4� �� ������ ���� #����5 ���

���)��� � � � ���

• �� � �� "��� ������������$������

• ������������ �������� ����������

• �����D*������������������ �������� �����6����

• � ������� �)��������

• '�� #������ �)��������

• ������ ���� ���� �� 6��� �� (��� ��$)�� ����

;+,-=#��$���

��������� �� ������#� �����6��)����������� ���� ������

�����E�����C�������6��)� ��� $)��3�������� ������������

6�)�� �� ���� ������ *������ $��������� ���� ����� ����

$����� $ �����#���� ���������������� ��D���� �������

6������D#��$�>��������$���������������

4�����������������5��������$������5 �����$$�����

������)�#����������������5 ��� ����# ��� ��� ## ��������

�����������

Page 6: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

!���� ��������������)�� ��������������2�3��&&!�

1 Public and Private Key Generation

�� ��������� ��$���������#���� � ����� �������� ������� ������������ �������������

�� �������������������)��� ������� ��6��� ������$�� ����������������:���

)��#��$������� �����D����� ����������� ���������������������������������� )��� ����

����� ����#�����>��� 4���$��������������)���� ������������������� ���������������

)��� �� 6��� ��� ��$�� �))� ��� ��� )���� >�5����� #��� 5��� �))� ��� ���� 6��� $��� ���

�����$���������5 ��������

4���#����5 ���#���� ��������������������� �������� ������������������������$��������

�)�� # �������� ��� 4� ��#���� �������� ���6���#���� ������� ���������������$)�� ����

(������� �����������6�������� "���#��������������� ��$������)���$�������������������

����������)��� ���6���

Page 7: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

/���� ��������������)�� ��������������2�3��&&!�

(�5����@�����6��������������)��� ��������

/**

* Generates the keys for given size.

* @param size - Key Size [512|1024]

*/

public void generateKeys(int size) {

try {

System.out.println("Generating Keys");

keyGen = KeyPairGenerator.getInstance("RSA");

keyGen.initialize(size);

keypair = keyGen.genKeyPair(); //Get the KeyPair for given algorithm and size.

privateKey = keypair.getPrivate(); //Extract Private Key

publicKey = keypair.getPublic(); // Extract Public Key

// Get bytes of the public and private keys

byte[] privateKeyBytes = privateKey.getEncoded(); //Get the key bytes

byte[] publicKeyBytes = publicKey.getEncoded(); // Get the key bytes

//write bytes to corresponding files after encoding them to Base 64 using Base64Encoder Class.

writeKeyBytesToFile(new BASE64Encoder().encode(privateKeyBytes).

getBytes(), PRIVATE_KEY_FILE);

String encodedValue = new BASE64Encoder().encode(publicKeyBytes);

writeKeyBytesToFile(encodedValue.getBytes(), PUBLIC_KEY_FILE);

//Generate the Private Key, Public Key and Public Key in XML format.

PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(new

PKCS8EncodedKeySpec(privateKeyBytes));

PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new

X509EncodedKeySpec(publicKeyBytes));

//Create and Instance of RSAPublicKey class with X509 encoding

RSAPublicKey rsaPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").

generatePublic(new X509EncodedKeySpec(publicKeyBytes));

//Get the RSAPublicKey as XML store the public key in XML string to make compatible .Net public

key file. See getRSAPublicKeyAsXMLString() for details

String xml = getRSAPublicKeyAsXMLString(rsaPublicKey);

Page 8: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

F���� ��������������)�� ��������������2�3��&&!�

//Store the XML (Generated .Net public key file) in file

writeKeyBytesToFile(xml.getBytes(), DOT_NET_PUBLIC_KEY_FILE);

}

catch (java.security.NoSuchAlgorithmException e) {

System.out.println("No such algorithm. Please check the JDK version."+e.getCause());

}

catch (java.security.spec.InvalidKeySpecException ik) {

System.out.println("Invalid Key Specs. Not valid Key files."+ ik.getCause());

}

catch (UnsupportedEncodingException ex) {

System.out.println(ex);

}

catch (ParserConfigurationException ex) {

System.out.println(ex);

}

catch (TransformerException ex) {

System.out.println(ex);

}

catch (IOException ioe) {

System.out.println("Files not found on specified path. "+ioe.getCause());

}

}

G��������6�����������������������������������������)�� # ��)���� ����� $)���# ������

��� ����8������� ����#��� ������������� ��6������� �������������)��#��$�����4�����

$����������9� ��$������������������5�6���������� $��#����������9������#�����5����

����������������6���������� $������� ���6���� ��#���� ��������� $�� ��$� ��#���� ���

��� ��������))� ��� �����#����� �� ������������

Page 9: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

%���� ��������������)�� ��������������2�3��&&!�

2 Public and Private Key initialization from stored files

:����5 ����5��#���� �������������)��� ������)� �����6�������������������������� ���

��������������������9� ����� )� ����� 6��� 4����#���� �� ����� )��� ���������� � �����

#���� ��� ��� � � �� "�� ��������� )� ����� 6��� 4��� ��� ��5��6� #��5��#��� ��#���� ��� ��

����� ���� ������# �����

Page 10: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

0���� ��������������)�� ��������������2�3��&&!�

-��@�� ���6� ��� ���� ����� ��5� ��� ��� ��$�� �� �� ������ ���� � � �� "��� �������� �����

� � �� "������� )� ����� 6������� #�����5 ������ � � �� "������� )� ��������� )��� �� 6���

���6������������#���� �����$������ � � �� "������

/**

* Initialize only the private key.

*/

private void initializePrivateKey() {

try {

//Read key files back and decode them from BASE64

BASE64Decoder decoder = new BASE64Decoder();

byte[] privateKeyBytes = decoder.decodeBuffer(new String(

readPrivateKeyFile()));

// Convert back to public and private key objects

KeyFactory keyFactory = KeyFactory.getInstance("RSA");

EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKeyBytes);

privateKey = keyFactory.generatePrivate(privateKeySpec);

}

catch (IOException io) {

System.out.println("Private Key File Not found."+io.getCause());

}

catch (InvalidKeySpecException e) {

System.out.println("Invalid Key Specs. Not valid Key files."+ e.getCause());

}

catch (NoSuchAlgorithmException e) {

System.out.println("There is no such algorithm. Please check the JDK ver."+ e.getCause());

}

}

/**

* Initializes the public and private keys.

*/

private void initializeKeys() {

try {

//Read key files back and decode them from BASE64

BASE64Decoder decoder = new BASE64Decoder();

byte[] privateKeyBytes = decoder.decodeBuffer(new String(

readPrivateKeyFile()));

byte[] publicKeyBytes = decoder.decodeBuffer(new String(readPublicKeyFile()));

// Convert back to public and private key objects

Page 11: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

1���� ��������������)�� ��������������2�3��&&!�

KeyFactory keyFactory = KeyFactory.getInstance("RSA");

EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKeyBytes);

privateKey = keyFactory.generatePrivate(privateKeySpec);

EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyBytes);

publicKey = keyFactory.generatePublic(publicKeySpec);

}

catch (IOException io) {

System.out.println("Public/ Private Key File Not found."+ io.getCause());

}

catch (InvalidKeySpecException e) {

System.out.println("Invalid Key Specs. Not valid Key files."+ e.getCause());

}

catch (NoSuchAlgorithmException e) {

System.out.println("There is no such algorithm. Please check the JDK ver."+ e.getCause());

}

}

Page 12: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

&���� ��������������)�� ��������������2�3��&&!�

3 Signing the Data

��� �� ���� �����#��$�����#���� �����$�������#���� ��� �����)��� ����#���� �� �������

��������������������� �������� ��#���� ��� ������ �������)� �����6��� � � �� "�� ��� ��

$����B ���������������7 �� ���)� �����6�����������������5�)� �����6����

Page 13: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

���� ��������������)�� ��������������2�3��&&!�

/**

* Signs the data and return the signature for a given data.

* @param toBeSigned Data to be signed

* @return byte[] Signature

*/

public byte[] signData(byte[] toBeSigned)

{

if (privateKey == null) {

initializePrivateKey();

}

try {

Signature rsa = Signature.getInstance("SHA1withRSA");

rsa.initSign(privateKey); //initialize the signature with provided key

rsa.update(toBeSigned); //sign the data

return rsa.sign(); //return the signature in bytes

}

catch (NoSuchAlgorithmException ex) {

System.out.println(ex);

}

catch (InvalidKeyException in) {

System.out.println("Invalid Key file.Please chekc the key file path"+ in.getCause());

}

catch (SignatureException se) {

System.out.println(se);

}

return null;

}

Page 14: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

����� ��������������)�� ��������������2�3��&&!�

4 Verify data and Signature

'�� #� ������������ ��#� ����� $)���4���#����5 ���#���� ��� �����)��� ����#������ #� ���

����� ��������#���������)��� �������3���������������4���� �������� ����� # ���5 �������

���� ������

/**

* Verifies the signature for the given bytes using the public key.

* @param signature Signature

* @param data Data that was signed

* @return boolean True if valid signature else false

*/

public boolean verifySignature(byte[] signature, byte[] data) {

try {

initializeKeys(); // Initialize the keys before verifying the signature

sign.initVerify(publicKey); //Initialize the signature engine instance with public key

sign.update(data); // load the data to be verified

return sign.verify(signature); // verify the data loaded in previous step with given signature and

return the

//result

}

catch (SignatureException e) {

e.printStackTrace();

}

catch (InvalidKeyException e) {

}

return false;

}

Page 15: Porting Java Public Key PDF

���� ������� �� ������������ ��.����

����� ��������������)�� ��������������2�3��&&!�

Page 16: Porting Java Public Key PDF

���� ������ ������ ���(�����$)�� �������� ��6����� ���.����

!���� ��������������)�� ��������������2�3��&&!�

Section 3: Generating .Net compatible Public Key

1 Net RSA Public Key XML

(���*������� ����������� ���,������������7)������5� �����������7��������#��$�����

.�������� ��6���A�#����5�����6� ��������.������������� �����������6��������+,-�5� ���

������������#��$��� ��������*������$����������������

4���,���������)������������,�������)���$�����#�������*�������� ��$�5� ���

B7)������ ��)�������� ���� B7)������ )���$����� #��� ���� *��� ����� ��$� 4��� *���

����� ��$������� ��(��� ����� ������������������$��)����

������ �������� ����������� ����

4���(���*������� ��+,-�6������������� ��� ��������5�

H�7$������ ��IJ&J������ ��IJK4:80J�L�

H*�����'����L�

H,������L���M&5 F��-K�*(#F�$9*��"D�-7�'&-> ���N*&-�'�+"0N%�N��)�

�6�>).�0K�0�7/�."�A �?<�E����&)��%KOII�

HD,������L�

HB7)�����L�O�AHDB7)�����L�

HD*�����'����L�

Page 17: Porting Java Public Key PDF

���� ������ ������ ���(�����$)�� �������� ��6����� ���.����

/���� ��������������)�� ��������������2�3��&&!�

2 Generating .Net XML Public Key from Java

����� ������ ���5��5 ���� ����������$��������������)��������7)��������.����)��� ��6���

���������(�����$)�� ����)��� ��6���4����7)������+,-�6���5 ������������������� ������

(����))� ��� �������5��5 ������ #������� ������������� ����� ��6���

-��@�����6�������������

*������#��$��������� ������ ���)������������5�� ���6�����$��#���� ����������������

�������� ��6��� ��+,-�#��$���

//Create and Instance of RSAPublicKey class with X509 encoding key specs

RSAPublicKey rsaPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").

generatePublic(new X509EncodedKeySpec(publicKeyBytes));

//Get the RSAPublicKey as XML store the public key in XML string to make compatible .Net public

key file. See getRSAPublicKeyAsXMLString() for details

String xml = getRSAPublicKeyAsXMLString(rsaPublicKey);

//Store the XML (Generated .Net public key file) in file

writeKeyBytesToFile(xml.getBytes(), DOT_NET_PUBLIC_KEY_FILE);

�#�������������# ����� ��3�+/&1B����������)������������������4� ����������)��������

���� ��(� ����� ��� �#� �� )��� �� 6��3� �������� ������ ��� ��� ���� ��(� ��)��

���C������� ������#��4������C������� ������#�������7� ����# ���� ������+/&1�

������������#����5���

���C������� ������#����I��BOKB(2B�P�

����� ��$������ ��$����� # ��3�

���C������� �����A�4��4*�( �Q�

(�5����6��������#���� �����$���������*������ ������+,-��� ���

/**

* Gets the RSA Public key as XML string.

* @param key RSAPublicKey

* @return String XML representation of RSA Public Key.

* @throws UnsupportedEncodingException

* @throws ParserConfigurationException

Page 18: Porting Java Public Key PDF

���� ������ ������ ���(�����$)�� �������� ��6����� ���.����

F���� ��������������)�� ��������������2�3��&&!�

* @throws TransformerException

*/

private String getRSAPublicKeyAsXMLString(RSAPublicKey key) throws

UnsupportedEncodingException, ParserConfigurationException, TransformerException {

Document xml = getRSAPublicKeyAsXML(key);

Transformer transformer =

TransformerFactory.newInstance().newTransformer();

StringWriter sw = ��5�StringWriter();

transformer.transform(��5�DOMSource(xml), ��5�StreamResult(sw));

�������sw.getBuffer().toString();

}

/**

* Gets the RSA Public Key as XML. The idea is to make the key readable for

* .Net platform. The generated key is compatible with .Net key structure.

* @param key RSAPublicKey

* @return Document XML document.

* @throws ParserConfigurationException

* @throws UnsupportedEncodingException

*/

private Document getRSAPublicKeyAsXML(RSAPublicKey key) throws

ParserConfigurationException, UnsupportedEncodingException {

Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().

newDocument();

Element rsaKeyValue = result.createElement("RSAKeyValue");

result.appendChild(rsaKeyValue);

Element modulus = result.createElement("Modulus");

rsaKeyValue.appendChild(modulus);

byte[] modulusBytes = key.getModulus().toByteArray();

modulusBytes = stripLeadingZeros(modulusBytes);

// KeyManager.write("c:\\mod.c",

// new sun.misc.BASE64Encoder().encode(modulusBytes)); //Stored it for testing purposes

modulus.appendChild(result.createTextNode(

new String(new sun.misc.BASE64Encoder().encode(modulusBytes))));

Element exponent = result.createElement("Exponent");

rsaKeyValue.appendChild(exponent);

byte[] exponentBytes = key.getPublicExponent().toByteArray();

Page 19: Porting Java Public Key PDF

���� ������ ������ ���(�����$)�� �������� ��6����� ���.����

%���� ��������������)�� ��������������2�3��&&!�

// KeyManager.write("C:\\exponenet.c",

// new sun.misc.BASE64Encoder().encode(exponentBytes)); //stored it for testing purposes

exponent.appendChild(result.createTextNode(

new String(new sun.misc.BASE64Encoder().encode(exponentBytes))));

�������result;

}

4���������$��� �����#���� ��������5��������������������+,-�# ���5� �������� �������

���� ������ ��#��$�� �������������� ��# ����������>����� �6���������$� �����������

���5��6�

Page 20: Porting Java Public Key PDF

���� ���!��*��� ������� ������������� #� ������������ ��(���

0���� ��������������)�� ��������������2�3��&&!�

Section 4: Reading Public Key and verifying the Data in

.Net

����� ������ ���5��5 ���������������� ��6���5� ���5������������� ��)��� �������� ������

����.����)�����$�

1 Initialization

������������������3� � � �� "��*������$����������������RSACryptoServiceProvider.

PUBLIC_KEY="c:\\netpublic.key"; //Generated by Java Program

RSAKeyInfo = new RSAParameters();

RSA = new RSACryptoServiceProvider();

2 Reading Key

:����5 ���#���� �������������# ���#��$������)�� # ��)�������>���G���$�������

���5��6������$�������������+,-�# �������������$�����������������7)���������������

��� ������$������� ������2�������������� ����#��$�A���F!�������� ������$����

*������$�����,�����������*������$�����B7)�������$)�������$������#���� ���

�#�*��2��)������ ������ ���� �������������������)���$������#���*�������� ��$�

private void readKey()

{

// read the XML formated public key

try

{

XmlTextReader reader = new XmlTextReader(PUBLIC_KEY);

while(reader.Read())

{

if (reader.NodeType == XmlNodeType.Element)

{

if(reader.Name=="Modulus")

{

reader.Read();

modStr= reader.Value;

}

else if(reader.Name=="Exponent")

Page 21: Porting Java Public Key PDF

���� ���!��*��� ������� ������������� #� ������������ ��(���

1���� ��������������)�� ��������������2�3��&&!�

{

reader.Read();

expStr= reader.Value;

}

}

}

if(modStr.Equals("") ||expStr.Equals(""))

{

//throw exception

throw new Exception("Invalid public key");

}

RSAKeyInfo.Modulus = Convert.FromBase64String(modStr);

RSAKeyInfo.Exponent = Convert.FromBase64String(expStr);

RSA.ImportParameters(RSAKeyInfo);

}

catch(Exception e)

{

throw new Exception("Invalid Public Key.");

}

}

3 Verifying the Signature

4���� ������������������ # ������������,�����������B7)����������������)������#��$�

����+,-������������ ��*��2��)������ ������ ������� #�� ��������$������ ��

���6��������� #������� ��������#���� ��������������� # ��������)�� # ���� �������������

�����$)�� ��� ���������� ����������$)�����#��������)�� # ��������

public bool verifySignature(byte[] signature , string signedData)

{

byte[] hash = Convert.FromBase64String(signedData);

try

{

if(RSA.VerifyData(hash,"SHA1",signature))

{

//Console.WriteLine("The signature is valid.");

return true;

}

else

{

//Console.WriteLine("The signature is not valid.");

Page 22: Porting Java Public Key PDF

���� ���!��*��� ������� ������������� #� ������������ ��(���

�&���� ��������������)�� ��������������2�3��&&!�

return false;

}

}

catch(Exception e)

{

Console.WriteLine(e.Message);

return false;

}

}

Page 23: Porting Java Public Key PDF

���� ���!��*��� ������� ������������� #� ������������ ��(���

����� ��������������)�� ��������������2�3��&&!�

Page 24: Porting Java Public Key PDF

�����������

������ ��������������)�� ��������������2�3��&&!�

Glossary

��� ���������

��� � ������������������������������������ �������� �����������$ �����$������������

�� 9����� ���� # ��� ���� ������� - 6�� �� 5� ����� � �������3� ���� )��)���� �#� �� � � ����

� �������� ������������������������ �� � ��������� �������$�������������� ��5���������

���� ��� $�� ��� ��� � � ���� � ��������� ���� ��)�� ����� $)������� #��� �8��$$�����

�))� ��� ���� ���� ���� �� 6��� ��$)������ �#� $���� ������� ��� ��� ����$��� - 6�� ��

����5� ������ �������3���� � ����� ������������$�������#������������ �� ����

• ����������� � ������������� # ��3�� ������$)���� ����������������� )��� ��6���

������)��� ����������)� �����6������������������������� ��������

• �������������#�����3�����$ �������)� �����6��� ��6�)���������

• ��� �� �� #���� ��� �#� ���� ����� � ����� ���� ����� ���@�� ��� ��� $��� ��� ��� ����

� ��������#�����������������5����

• 4���� ���������������������������E� #� �@��������)��� ���� ��������5 ��� ���

���������� #������� ���������� ��

����� ������

��� ���� )��� �86��� �����)� �������� ��$�������)������*������������� ��3� ���� 4���

������$��������#���* ����3����$ �3���������$��3����� ����������#���������� 9���

4���*�������� ��$� ���������������#��������������� ������## � ����5������#�����������

��������$���������� ������*���6��3������#���3���9� ��������7������ ������$������#�

��$)�����)������ ���)�5�������� $��

4��� *��� ����� ��$� ���� ����$�� ���� ��� #����� ��������� #��� ������ ��8���������

�����)� ��3���)�� �����#�������������������������������

������������

4�����)�������� ����#���7�� ������#��$��#���� �������� ����#�� � ��3����������� �����

#��$����������������85��������#���� ���B����)� �����$�������� �����5 �����)� �����

6�������������� � ����� �������3�5� ��� ������������� ��$������#�������� ��� ���

������

Page 25: Porting Java Public Key PDF

�����������

������ ��������������)�� ��������������2�3��&&!�

������ �������������#��������� �����������#�������� ��� �������������;���� $)���

���=3����������������������������3� ������$��������������#��$������ ����#���7��4���

����� ���������� ������$�����������������7�� ����#3����� �����������������#��$���� ��

�������5�������� �� ���7���$������� 6�����������$����������7��5 ���)�������������$��

�����������

>������)����������� ������� ��������$��5���������R����������������������������$ �����

$�������� ����� ���� ����� ��$)����� 5 ��� 4��� ������� ���������� �� ����� �#� ����

$������3� �����)��� �3� ���� ������ �� 5 ��� ���� $������� ����#� 4��� ��� ) ���� �����

�����)������������$�������������������3�)���������������������#��$��������� ����

$������3�������$)����������5��������� �#�����R���������$�3������� ���������� ���

)����� � ��� ����� ���� $������� 5��� �����$ ����� ������ >��� ��� �� ����� �� ��$$���

$�������#������� ����������������2��� ���3�#����7�$)��3���� ����#���$����

• .�����$ ���

• ������.�����

• *��������$��

4������������ ���73��������������������#����������������3�����5������))�����#��$����

����������$�����)����������� 9�����$�� ���������������$ ����������$��� ���� 6���

• �!/0%��.�����$ ���

• �&1%1&/�������.�����

• !&F&1F!�*��������$��

4��������������#������������������� � ������������������C���������������))�������

#��$���3�5� ���� �������� ��������� ���7�6�����������������4� �� ��$����$�����## � ����

����������� ���������������������������� �������$���� ���������� ��#�����

��� ������

�� ��$���� ����� ����� 5 ��� �� )��� ������ ��� ��� ;#��� �7�$)��3� ��� �� � ����� ��� ���

����� "�� ��=���)��� ��6��� �� ��������������6��5���������������5�����������������

�������� ������� ����5 ����������� ���

�����������

Page 26: Porting Java Public Key PDF

�����������

�!���� ��������������)�� ��������������2�3��&&!�

����$��������� ����))�����������6��5������������)��� ��������� ���4���� �3�)� �����

6����������5����$�����������6�)�����������)� �����6��� ����5��������� �����5 �����

� �����)��� ��6���

������������� ������

�������� ��$������������)���������������$�����#�����#����5 ����

• 4������# ���� �� ����#������

• ������� ��� ����#�����������������

• ������ ����#���������������

• (�����)�� �� ��E������������������������� ����������)��� ������$�������

����������

4���)��������#���6 ��������;���������������=���������������� ���;�����=�����)����� ���

����������3�5� ��� �������$��� �������������� ��8)�����5������������6��5�����6���

����������

4��� ��������#������)� ��E�����)��������#���6 ���� )�����7��������������6������ ��3�

����)����� ����������7��

����������

��� � ������� ����� �����$���� #��$����� ��� ��3���� ��� ��������� )��� �� 6����#���$��

������ ��� ��� ���� ��$�� )��� ������ ������ �#� ���� ������ ���� ��� ��� ����� � ����� ��

���� # ����3� ���� ������ ����� ���� ����� �� ��� �� ���� ���� # ����� ���5���� ���� �)�� # ���

)��� ��6���������������)��� ��������� ��� ��������� ��

������������� ���������� ��!"��������#������$�

�� #���� ��� ����� ��6��� ��� �����8� "��� �)��� ����� ;��#������ ��� ��� ��������=� ����

������������# 7��8� "�����)��3�����������������;�������=���� �������������#����5 ���

)��)��� ����

• ���������������$)���� ������� �#��� �������# ����������� �)������ ��������5 ���

���������������$��� �����

• 4��� � ����� ����� ���� ������� ����� ��� ������ ���� �)��� ����� 5��� ����� ���

��������� ��

Page 27: Porting Java Public Key PDF

�����������

�/���� ��������������)�� ��������������2�3��&&!�

,������� � ����� ����� ��$�� ���� ����� ��� )������� �� 9��� ���� ��� ����� ���� # ���� �#�

�����4���� ������������$�� $��������������J� � ����# ����)� ���J��#������

��$��� � ����� ������������� ��$������$�������� ���������� ��$��#���)������#���� ��

��$)���� ����

��$��� � ����� �������������$����$)��������� ������#���$������������ � ������� ���

����� ������������������ �� �������$������� ����#�4� ������������������#�� $�3�� ����

� � ������� �� ����������$��������������� $�8�����$ ���

������ ����

4��� ���$� ������� ����� �� ����� �� ���� .���� ����� ��� ���� ��� ��#��� ��� �� ������ �����

)��� ���� ���� #���� ���� ��� �#� �� ��)�� �#� ���)�����)��� ����� ��$� 4��� ����� ��� ����

��# ������.����������#����������� ���������:����7�$)��3������� ����,������� �����

�����3���� �������������3������������ � ���������������K������#�����������9���������

�� � "�� ����������#������� ��� ��� ���������������������������)��� ����)���� ���� ��

� �������� �������� ������� ��� � ��� ���� ��� #��� � ���� � ��������3��� ,������� �����

�������� �� ����� ��� ���������� ���� $������� � ����� �#� �)�� # ��� ����3� ���� ��

����� � ��������� �������������������)� ����#�)��� ������)� �����6������ ������#�����

�)�� # �������� ��$�

��� ��� ��� ������ )��� ���� ���� ����#���� ��� ���� #���� ���� ��� �#� �� �)�� # �� ��)�� �#�

����� ��$3�5� ��� ���������� $)��$����� ����;#��$��������$����)��� ����=�����������

#����)�� # ������� ��$��4���� ����������� ��������3�#����7�$)��3�)��� ��������������

����#���� ���� ����#���� � ����� ������������� ��$�4���������� $)��$����� �����))� ���

����� �������������������������������#�������6 ����#�� ������������� ��$3���������

�>�8�5 ������3��>�8�5 ���*��3����,�/�5 ���*�����������������>�8�5 ���*���

����%���

�$)��$����� ���� #��� ��� ���� ����� ��$�� �� .���� ����� ��� ���� )��� ���� ���

������������ ����� ������������� ��������������� �����)��6���������� $)��$����

���� ��� $���� ��� ��� �������� #��� �)�� # �� ����� ��$�� :��� �7�$)��3� ���� .����

������)$����� �R����#�����)��� ������$���J�K(JE���))� ��� $)��$����� �����#�����

���� � �������� ����� ��$� ���� �#����� ,�/� ���� �>�8� $������� � ����� ����� ��$��

G����� )��� ����� $��� ��# ��� ��� �� �5�� $)��$����� ���� �#� ������ ����� ��$�� ��� �#�

����������� ��$�3��������������#�����*��8������� ������������� ��$���������,���

$�������� ���������� ��$�

Page 28: Porting Java Public Key PDF

�����������

�F���� ��������������)�� ��������������2�3��&&!�

"�������������&��������������'�����%�(�

4���.��������� ������� ������5�.������������3��� ��������������C�������� ���)��6����

;���� ������)��6����=� 4���# �������������#�����.��������� ������3���� ������ ��.���

3������ ��������#����

��� ����������

� � ���� � �������� ����� ��$�3� ����� ��� ���� ;� � ���� � �������� ����� ��$=� 4���

#���� ���� ��� �������� ������� ��� )��� �D)� ����� 6��� )� ��� ��� 5���� ��� � �� ��� ����

��� #� ������ ������� � ���������

�������������

2��)�����)� ������ ������� $������� � �����3� ����� ��� ,�/� ���� �>�8� 4�����

����� ��$�3����������������85������������� ��$�3��������#���#��� )����� ��� J� � ����

# ����)� ���J� �#� ����3� 5� ��� ���� #��9������� ����� �� � � ���� � ��������� ���� ������

�))� ��� ���������������� 9���������#��������� ���� # ����#���� � ����������

��������������

�������#��������� ����#���$���� ��� )� �� )����;��� � ����������� �� � ��������������

����)�=3���� ��6���3�������� ������ # �������������5���))� ��� ���������� ������ ���5��

6���$�����$���������$�3�������� �����)������5 ��������������$�������� ���������

(�����������))����#����)�� # ������ # �����#��$���� ��������� ����������5 ������)�����#���

#������.�����������

4��� ���)�����)���#��$�5��6� �� ���� .��������� ��� ���� �� ��� ����� ���������� ��5�

����� ��$�����������������������5 ������$����� ## ������������������� � "��� ������

��$��#��� �������7 �� �������� ��$��:����7�$)��3�������������� ������������� ��8 ��

� � ����� ������������� ��$� ���� ���������3�����#��$�5��6����� ��� �������$$������

�������� ����� ��$� ����� ��� *��� '������� ���� ������)� ��� �� �5�� ����� ��$�� ����

������������ �������� ���)��� ���=�)��6����� ��������.��������� ����������������� �����

������ � "�����$�

������ ������

)������������ ����

4��� � �������� ������ ����� ��� ��� ��������� ����� ��� )��� ��� ���� #���� ���� ��� �#���

� � ���� � �������� ����� ��$��������� ���� ���*���5 ���,�/� �� � �������� ����� ��$�

��6������ �����8� "��� �)���������)� �����6������������������������ �����������;�#����

Page 29: Porting Java Public Key PDF

�����������

�%���� ��������������)�� ��������������2�3��&&!�

# 7��8� "�=���� ����#������3������������� �������3�5 �������#����5 ���)��)��� ����

���� ���� )��� �� 6��� ������)��� ��� ��� ���� )� ����� 6��� ����� ��� ��������� ����

� �������3� ������������)��� ���������� #������������� � ������� ����� ����#����� �)���

4���� ���������������� )��� ��6���������������������� �������������)� �����6�����

� ����������C������������������������������� � ����� ��������#�����������������������

����������� #��5�������������������������� �������� �� ��#��������������� ��� ��������

�#��������������� �����5 ��� ��

)��������������� ����

4���,������� ����������� �������� ������������ ��������)��� �������#���� ���� ����#�

���)�����)� �������������,�������� �����,�������� ���������������>�8����,�/����

��6������ �����8� "��� �)���;������������=3�����������������# 7��8� "�����)��3����������

� �������� �������������#����5 ���)��)��� ����

• ���������������$)���� ������� �#��� �������# ����������� �)������ ��������5 ���

���������������$��� �����

• 4��� � ����� ����� ���� ������� ����� ��� ������ ���� �)��� ����� 5��� ����� ���

��������� ��

,�������� ������������������)��������� 9���������� ����� ���� # �����#������4��������

��$�� $��������������J� � ����# ����)� ���J��#������

����'����������

4������� ����#���� ��������)8������ ����#����#�������6���������# ��������#���� ���� ���

��������������6�����C���������6������������������������ �� ����

• �������� ��$�

• ���B�������:��$�

4� �� �� ��� �7������� �������� #��$� #��� ���� 6��� ����� 5���� �� ���������

��)�������� ����#�����6��� ������������� �������.����' ������,��� ��3����5����

�����$ �� �������6��������$��������)�����4���6��� ���������������� ��������

���������#��$���;��������+/&1������2�<0=�

• ��:��$���

4� �� �� ���� ��$�� �#� ���� #��$��� �#� ���� �������� 6������� ���� ����������

���� ������������6�������������3����� # �����3������� ��������� ����������������

���$������6����

Page 30: Porting Java Public Key PDF

�����������

�0���� ��������������)�� ��������������2�3��&&!�

)����������� ����

4�������� �������� ����� $)����������#�����6���)� ��;��)��� ��6���������)� �����6��=����

���� �5�� )��� �� $������3� ���� #��� ������ ��� ���� )� ����� 6��3� ���� ���� ������ #���

������ �������)��� ��6���

)���������*���������� ����

4�������� � ��������������� �������� ��������������������������)� ����#�)��� ������

)� �����6����

Page 31: Porting Java Public Key PDF

*�#��������

�1���� ��������������)�� ��������������2�3��&&!�

References

�)�� ��� 4���6�� ��� �� �� ����� S)��T5��5 �6��$)������6U� ?� ����� *� ����

+�������,����-��.�

���)�DD)���� ������DV�������D#������D.���(��D�

���/�0������

���)�DD$���$ �����#���$D� �����D��#������)����ID� �����D����D����) D��$�D�����)

������)�����)�

���/��123�

���)�DD555�������!%��$D�!%��#������D$���D�FD0!!1��)7�

Page 32: Porting Java Public Key PDF

�������������

�&���� ��������������)�� ��������������2�3��&&!�

About Author

���������� 2�������� �)�� �� "��� �� ���� �������3� ��� ��3� ������)$���� ����

��)���$�����#�.�BB�����(��������)� ����))� ��� ����>���������6���5 ��������)� ���

�))� ��� ���������)$������� ���� ��������� ��������������������������� �������� ����

��������������A���������������� ��2�$)������� �����;,�C��� ����#�5����B���=�#��$�

,���$$����� �. �����K� ���� ��3�����$����8��6 ������