小编Dim*_*tri的帖子

Android 8.0:使用RSA/ECB/OAEPWithSHA-512AndMGF1Padding时出现IllegalBlocksizeException

我通常会在这里找到大部分问题的答案,但这次我需要问:-).

我们在Android 8.0(API级别26)上运行的某个应用程序中遇到了RSA加密/解密问题.

我们一直在使用带有"RSA/ECB/OAEPWithSHA-256AndMGF1Padding"的RSA,它适用于Android 7.1以上的所有版本.在调用Cipher.doFinal()时,在Android 8.0上运行的相同代码会抛出IllegalBlocksizeException.

以下是重现问题的代码:

private KeyStore mKeyStore;

private static final String KEY_ALIAS = "MyKey";
void testEncryption() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyStoreException, IOException, CertificateException, BadPaddingException, IllegalBlockSizeException, InvalidKeyException, UnrecoverableEntryException, NoSuchPaddingException {

    mKeyStore = KeyStore.getInstance("AndroidKeyStore");
    mKeyStore.load(null);

    // Generate Key Pair -------------------------------------
    KeyPairGenerator kpg = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore");
    kpg.initialize(new KeyGenParameterSpec.Builder(
            KEY_ALIAS,
            KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
            .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP)
            .setKeySize(2048)
            .build());
    KeyPair kp = kpg.generateKeyPair();

    // Encrypt -----------------------------------------------
    KeyStore.PrivateKeyEntry privateKeyEntry = (KeyStore.PrivateKeyEntry)mKeyStore.getEntry(KEY_ALIAS, null);
    PublicKey publicKey = (PublicKey) privateKeyEntry.getCertificate().getPublicKey();
    Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
    cipher.init(Cipher.ENCRYPT_MODE, publicKey); …
Run Code Online (Sandbox Code Playgroud)

encryption android rsa padding

10
推荐指数
1
解决办法
2556
查看次数

iOS / Swift:在 UITextFields 键盘上显示电子邮件地址建议

在我们的 iOS / iPhone 应用程序之一中,我们需要在注册过程中显示用户配置的电子邮件地址作为建议。有多个应用程序将电子邮件地址显示为键盘输入附件视图中的固定按钮。以 Yelp 应用程序为例(配备 iOS 13.4 的 iPhone 8)

在运行 iOS 13.4 的 iPhone 8 上使用 Yelp

我无法弄清楚如何使用内置方法启用此功能。我尝试将 textContentType、keyboardType 和 auto CorrectionType 设置为正确的值,如我能找到的有关此主题的其他堆栈溢出文章中所述。

这是我的代码

    override func viewDidLoad() {
    super.viewDidLoad()

    let email = UITextField(frame: CGRect(x: 10, y: 60, width: 300, height: 40))
    email.placeholder = "Enter email address here"
    email.font = UIFont.systemFont(ofSize: 15)
    email.borderStyle = UITextField.BorderStyle.roundedRect
    email.clearButtonMode = UITextField.ViewMode.whileEditing
    email.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
    email.returnKeyType = .continue

    email.keyboardType = .emailAddress
    email.textContentType = .emailAddress
    email.autocorrectionType = .yes
    email.autocapitalizationType = .none

    view.addSubview(email)
}
Run Code Online (Sandbox Code Playgroud)

这是我在运行 Yelp 应用程序时在运行 iOS 13.4 的同一台 iPhone 8 …

email-address uitextfield ios inputaccessoryview swift

5
推荐指数
1
解决办法
5340
查看次数