54
55 import javax.crypto.BadPaddingException;
56 import javax.crypto.Cipher;
57 import javax.crypto.CipherSpi;
58 import javax.crypto.SecretKey;
59 import javax.crypto.IllegalBlockSizeException;
60 import javax.crypto.NoSuchPaddingException;
61 import javax.crypto.ShortBufferException;
62
63 import javax.crypto.spec.SecretKeySpec;
64
65 import sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec;
66 import sun.security.util.KeyUtil;
67
68 /**
69 * Asymmetric Cipher wrapper class utilizing ucrypto APIs. This class
70 * currently supports
71 * - RSA/ECB/NOPADDING
72 * - RSA/ECB/PKCS1PADDING
73 *
74 * @since 1.9
75 */
76 public class NativeRSACipher extends CipherSpi {
77 // fields set in constructor
78 private final UcryptoMech mech;
79 private final int padLen;
80 private final NativeRSAKeyFactory keyFactory;
81 private AlgorithmParameterSpec spec;
82 private SecureRandom random;
83
84 // Keep a cache of RSA keys and their RSA NativeKey for reuse.
85 // When the RSA key is gc'ed, we let NativeKey phatom references cleanup
86 // the native allocation
87 private static final Map<Key, NativeKey> keyList =
88 Collections.synchronizedMap(new WeakHashMap<Key, NativeKey>());
89
90 //
91 // fields (re)set in every init()
92 //
93 private NativeKey key = null;
94 private int outputSize = 0; // e.g. modulus size in bytes
|
54
55 import javax.crypto.BadPaddingException;
56 import javax.crypto.Cipher;
57 import javax.crypto.CipherSpi;
58 import javax.crypto.SecretKey;
59 import javax.crypto.IllegalBlockSizeException;
60 import javax.crypto.NoSuchPaddingException;
61 import javax.crypto.ShortBufferException;
62
63 import javax.crypto.spec.SecretKeySpec;
64
65 import sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec;
66 import sun.security.util.KeyUtil;
67
68 /**
69 * Asymmetric Cipher wrapper class utilizing ucrypto APIs. This class
70 * currently supports
71 * - RSA/ECB/NOPADDING
72 * - RSA/ECB/PKCS1PADDING
73 *
74 * @since 9
75 */
76 public class NativeRSACipher extends CipherSpi {
77 // fields set in constructor
78 private final UcryptoMech mech;
79 private final int padLen;
80 private final NativeRSAKeyFactory keyFactory;
81 private AlgorithmParameterSpec spec;
82 private SecureRandom random;
83
84 // Keep a cache of RSA keys and their RSA NativeKey for reuse.
85 // When the RSA key is gc'ed, we let NativeKey phatom references cleanup
86 // the native allocation
87 private static final Map<Key, NativeKey> keyList =
88 Collections.synchronizedMap(new WeakHashMap<Key, NativeKey>());
89
90 //
91 // fields (re)set in every init()
92 //
93 private NativeKey key = null;
94 private int outputSize = 0; // e.g. modulus size in bytes
|