Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CipherSource can't support RSA? #1555

Open
kagg886 opened this issue Dec 5, 2024 · 1 comment
Open

CipherSource can't support RSA? #1555

kagg886 opened this issue Dec 5, 2024 · 1 comment

Comments

@kagg886
Copy link

kagg886 commented Dec 5, 2024

exception is

Block cipher required Cipher.RSA/ECB/NoPadding, mode: encryption, algorithm from: SunJCE
java.lang.IllegalArgumentException: Block cipher required Cipher.RSA/ECB/NoPadding, mode: encryption, algorithm from: SunJCE
	at okio.CipherSource.<init>(CipherSource.kt:32)
	at okio.Okio__JvmOkioKt.cipherSource(JvmOkio.kt:205)
	at okio.Okio.cipherSource(Unknown Source)

my usage is this:

val rsaCipher = Cipher.getInstance("RSA/ECB/NoPadding").apply {
                            init(
                                Cipher.ENCRYPT_MODE,
                                KeyFactory.getInstance("RSA").generatePublic(
                                    RSAPublicKeySpec(
                                        BigInteger(
                                            "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7",
                                            16
                                        ),
                                        BigInteger(
                                            "010001",
                                            16
                                        )
                                    )
                                )
                            )
                        }

 randomString(16).byteInputStream().source()
                                            .cipherSource(rsaCipher).buffer()
                                            .readByteString().hex().take(256),

then run the code, error occured

@swankjesse
Copy link
Collaborator

You’ll need to find a hybrid encryption implementation to do asymmetric keys with a stream. Here’s a quick overview on doing it with Tink: https://www.baeldung.com/google-tink#hybrid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants