rsakeygen.java

来自「java applet code for generating RSA key 」· Java 代码 · 共 67 行

JAVA
67
字号
package RSA;import javacard.framework.*;import javacard.security.*;import javacardx.crypto.*;public class RSAKeyGen extends Applet {	// code of CLA byte in the command APDU header	  final static byte CLA =(byte)0x80;	  // codes of INS byte in the command APDU header	  final static byte INS_CREATE_RSA_KEYPAIR = (byte) 0x20;	  // RSA	  private KeyPair rsaPair;	  private RSAPublicKey rsaPubKey;	  private RSAPrivateKey rsaPrivKey;	  public static void install(byte[] bArray, short bOffset, byte bLength)		{			new RSAKeyGen(bArray, bOffset, bLength);		}	  /**	  * Performs memory allocations, initialization, and applet registration.	  *	  * @param bArray to pass to register() method.	  * @param bOffset to pass to register() method.	  * @param bLength to pass to register() method.	  */		protected RSAKeyGen(byte[] bArray, short bOffset, byte bLength)		{			rsaPair = new KeyPair(KeyPair.ALG_RSA_CRT,(short)1024);			register();		}	  /**	  * Dispatches APDU commands.	  * @param apdu APDU object	  */		public void process(APDU apdu)		{	    if (selectingApplet())	        return;	    byte[] buffer = apdu.getBuffer();	    if (buffer[ISO7816.OFFSET_CLA] != CLA)	       ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);	    switch (buffer[ISO7816.OFFSET_INS]) {	      case INS_CREATE_RSA_KEYPAIR:	      	genRSAKeyPair(apdu);	      	return;	      default:	      	ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);	    }		}	    public void genRSAKeyPair(APDU apdu) {			rsaPair.genKeyPair();	   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?