コード例 #1
0
ファイル: P11RSACipher.java プロジェクト: ronshapiro/j86
 private void implInit(int opmode, Key key) throws InvalidKeyException {
   cancelOperation();
   p11Key = P11KeyFactory.convertKey(token, key, algorithm);
   boolean encrypt;
   if (opmode == Cipher.ENCRYPT_MODE) {
     encrypt = true;
   } else if (opmode == Cipher.DECRYPT_MODE) {
     encrypt = false;
   } else if (opmode == Cipher.WRAP_MODE) {
     if (p11Key.isPublic() == false) {
       throw new InvalidKeyException("Wrap has to be used with public keys");
     }
     // No further setup needed for C_Wrap(). We'll initialize later if
     // we can't use C_Wrap().
     return;
   } else if (opmode == Cipher.UNWRAP_MODE) {
     if (p11Key.isPrivate() == false) {
       throw new InvalidKeyException("Unwrap has to be used with private keys");
     }
     // No further setup needed for C_Unwrap(). We'll initialize later
     // if we can't use C_Unwrap().
     return;
   } else {
     throw new InvalidKeyException("Unsupported mode: " + opmode);
   }
   if (p11Key.isPublic()) {
     mode = encrypt ? MODE_ENCRYPT : MODE_VERIFY;
   } else if (p11Key.isPrivate()) {
     mode = encrypt ? MODE_SIGN : MODE_DECRYPT;
   } else {
     throw new InvalidKeyException("Unknown key type: " + p11Key);
   }
   int n = (p11Key.length() + 7) >> 3;
   outputSize = n;
   buffer = new byte[n];
   maxInputSize = ((padType == PAD_PKCS1 && encrypt) ? (n - PKCS1_MIN_PADDING_LENGTH) : n);
   try {
     initialize();
   } catch (PKCS11Exception e) {
     throw new InvalidKeyException("init() failed", e);
   }
 }
コード例 #2
0
ファイル: P11RSACipher.java プロジェクト: ronshapiro/j86
 // see JCE spec
 protected int engineGetKeySize(Key key) throws InvalidKeyException {
   int n = P11KeyFactory.convertKey(token, key, algorithm).length();
   return n;
 }