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

decrypt bytea string #3

Open
emacielxp opened this issue May 25, 2021 · 0 comments
Open

decrypt bytea string #3

emacielxp opened this issue May 25, 2021 · 0 comments

Comments

@emacielxp
Copy link

emacielxp commented May 25, 2021

can help me with the error below:

public key

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: BCPG v1.61

mQENBGCtACABCADIs8IRd05slPHXjcu3WGVY8dQwPHnkIyMgfnEsURRkIlbyXVVY
f2gH5yjndgfD9Sw3yWhVViZWozdmAT8UV2pHk4qCiCd83WiGC1pkOEw2GS4If3cT
EU7dJC5P/Py0FuVYrMdgZiGJGvbTIvHOsm14RnzxSWvzI8EwXVGdqczV7I5d4My3
PRuSE+PTaA7XE05efik1ovl7FSSU7BxvjsjnIn8nw+ddujOE94SA7cgmIWufHUFx
QqjsabT1NaVcEYw1qu9C1vtje+MUm0XyXVfYUpzPKypGu59DsT4UlFX29Q4wiIvB
YEGf2STDFOuKV5nlDxZqYe69CrW19ztuyYUrABEBAAG0HWNoYXZlX3Rlc3RlIDxl
bWFpbEB0ZXN0ZS5jb20+iQEuBBMBCgAYBQJgrQAlAhsDBAsJCAcGFQgCCQoLAh4B
AAoJECjVvFZzfEY/hk8H/3AH+f6YcP5VR1WKGAMKGWJKHhX6BwVY2fBYT40dxqMH
Ee0PIeED7JvABUOGFTwVk4Uqa7RZYnvQkaQG32LxdHHj4G6T5bsNpwRzAhHhrm4D
PvDtCVe7ztBv63KkWpHveCDYzqOCcRcIePQSla/5+wgtzUX+/2QJnOye7tzoJCXf
RrP2hT1HvdRiPATena83wTmn5XM2fDDFiBqF2dA1VwYXaxAk5VGr3HH8LeWdcunB
6B9FVO/4Pno6OdtPBPheewmkpn65ciNPrekBY5QBrF0SisQSuNkX+R2ltrgd+sP7
bjkQ5o1maKJGCuispT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1iAfaA=
=wZ6X
-----END PGP PRIVATE KEY BLOCK-----

those keys are generated with this command:

KotlinPGP.generateKeyPair(
                GenerateKeyData("chave_teste", "[email protected]", "123456", KeyData(2048, Algorithm.RSA), KeyData(2048, Algorithm.RSA))
            )

and retrieved by: keyPair.publicKey and keyPair.secretKey

at postgresql, i used the publickey string to encrypt a text and encode the encrypted result as base64. use this command:
select encode(postgis.pgp_pub_encrypt('string to be encrypted and encoded', postgis.dearmor('public key string')), 'base64')

the result is:
wcDMA/nLwh3roOyyAQv+IlIO+6cmGWQ4NoPYafgrxhfT2mhJfXX5cNAqFwPqE2LlIduqVf6wci+fJosLpcgEP2W38XCw0Q+NtsrUCINUph+5QDlFXK48sd6drSAGdRlrvxp9Mq2iOlALzX6ZaK3vRLpVcEMHZBC8eQRmXxX8l4t8qVlxGNHv04fmhFcYL5pi5L39ei7DPcxiW3O/kat8Wrm1RhjmXTcSXq43PjcwgOsw2nh6BIt/ZVdXuYm9RCdaNTkSNFVd8MgwokF1lMnL6DhZTMw7itdaepCE3LQ/z7nxgsqf64d69GWb4DFRtPpzbRRxqIkjZxxF+tpCNIB8zjz/9v35+SPnc9rg5tioTVTmYlLTKZpBjGei91RGLZt5ZbsrP1doGYM8QD4Hd5U9oH8lkrS/ArpxqWOuR9Be2Nw2bIUQ5+NmmPPrD0O6EiumabwWo1il95EkMc74uQpM0nvsVdiNrzFSSVQnZxfHZiQIAipj5C1YFEsx4DzbbHR7Sjp4Cd5G0G2zJlF59QTS0kcBSkV0bG894+6A2CEpJniA5i/+YdFdUFz3LOq+5In5Ob4DamRJl+TNNylqUFZQhBWfzuvwgjbs+BConxGayYfuteHK64R+gQ==

when i try to decrypt this use my secret key i receive an error, see below the code used:

val decodedBytes = Base64.decode("wcDMA/nLwh3roOyyAQv+IlIO+6cmGWQ4NoPYafgrxhfT2mhJfXX5cNAqFwPqE2LlIduqVf6wci+fJosLpcgEP2W38XCw0Q+NtsrUCINUph+5QDlFXK48sd6drSAGdRlrvxp9Mq2iOlALzX6ZaK3vRLpVcEMHZBC8eQRmXxX8l4t8qVlxGNHv04fmhFcYL5pi5L39ei7DPcxiW3O/kat8Wrm1RhjmXTcSXq43PjcwgOsw2nh6BIt/ZVdXuYm9RCdaNTkSNFVd8MgwokF1lMnL6DhZTMw7itdaepCE3LQ/z7nxgsqf64d69GWb4DFRtPpzbRRxqIkjZxxF+tpCNIB8zjz/9v35+SPnc9rg5tioTVTmYlLTKZpBjGei91RGLZt5ZbsrP1doGYM8QD4Hd5U9oH8lkrS/ArpxqWOuR9Be2Nw2bIUQ5+NmmPPrD0O6EiumabwWo1il95EkMc74uQpM0nvsVdiNrzFSSVQnZxfHZiQIAipj5C1YFEsx4DzbbHR7Sjp4Cd5G0G2zJlF59QTS0kcBSkV0bG894+6A2CEpJniA5i/+YdFdUFz3LOq+5In5Ob4DamRJl+TNNylqUFZQhBWfzuvwgjbs+BConxGayYfuteHK64R+gQ==", Base64.DEFAULT)

val decodedString = String(decodedBytes)

val decryptResult = KotlinPGP.decrypt(
                secretKey,
                "123456",
                decodedString
)

decoded string from base64 converted to string (decodedString):

�������������"R���&�d86��i�+����hI}u�p�*����b�!۪U��r/�&�����?e��p�������T���@9E\�<�ޝ� �u�k��}2��:P��~�h��D�UpC�d��y�f_����|�Yq���Ӈ�W�/�b��z.�=�b[s���|Z��F��]7�^�7>70��0�xz���eWW���D'Z59�4U]��0�Au����8YL�;��Zz��ܴ?Ϲ�ʟ�z�e��1Q��sm�q��#g�E��B4�|�<�����#�s���بMT�bR�)�A�g��TF-�ye�+?Wh��<@>�w�=��%�����q�c�G�^��6l����f����C��+�i���X���$1���
    L�{�U؍�1RIT'g��f�*c�-X�K1�<�lt{J:x	�F�m�&Qy����G�JEtlo=���!)&x��/�a�]P\�,���9��jdI���7)jPVP�������6�������ɇ����~�

below the stacktrace of the error:

2021-05-25 10:54:16.692 13576-13576/com.example.pocpgpandroid E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.pocpgpandroid, PID: 13576
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
     Caused by: java.io.IOException: unknown object in stream: 47
        at org.bouncycastle.openpgp.PGPObjectFactory.nextObject(Unknown Source:36)
        at moe.tlaster.kotlinpgp.KotlinPGP.encryptedDecryptResult(KotlinPGP.kt:256)
        at moe.tlaster.kotlinpgp.KotlinPGP.decrypt(KotlinPGP.kt:246)
        at com.example.pocpgpandroid.FirstFragment.onViewCreated$lambda-2(FirstFragment.kt:142)
        at com.example.pocpgpandroid.FirstFragment.lambda$b3jqjhg7e5sn5psKJ4hBYyBV4pU(Unknown Source:0)
        at com.example.pocpgpandroid.-$$Lambda$FirstFragment$b3jqjhg7e5sn5psKJ4hBYyBV4pU.onClick(Unknown Source:2)
        at android.view.View.performClick(View.java:7448)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
        at android.view.View.performClickInternal(View.java:7425)
        at android.view.View.access$3600(View.java:810)
        at android.view.View$PerformClick.run(View.java:28305)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
2021-05-25 10:54:16.746 13576-13576/com.example.pocpgpandroid I/Process: Sending signal. PID: 13576 SIG: 9
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

1 participant