terl / lazysodium-java

A Java implementation of the Libsodium crypto library. For the lazy dev.
https://github.com/terl/lazysodium-java/wiki
Mozilla Public License 2.0
134 stars 46 forks source link

help using sealed box for GitHub secret #125

Open JonGilmore opened 1 year ago

JonGilmore commented 1 year ago

I'm trying to use this to encrypt a GitHub secret (reference) using sealed boxes, but am getting 500's back from the enterprise github server when I actually make the HTTP PUT call. Here's my function that I'm using to encrypt:

  fun encryptSecret(secret: String): String {
    val pub = "MyGhPubKeyThatIveRemoved"
    return Base64.getEncoder().encodeToString(
      LazySodiumJava(SodiumJava(), StandardCharsets.UTF_8).cryptoBoxSealEasy(
        secret, Key.fromPlainString(pub)
      ).toByteArray()
    )

I'm not actually sure if I'm encrypting wrong, or if there's another issue with my code, the 500 that I get back from GitHub doesn't seem too helpful so far. FYI, this function is largely derived from here.

Martijnpold commented 1 year ago

Old issue, but I found this article that was really helpful to get it working for me. In my case, I was encoding strings in the wrong way.

https://philiplimbeck.dev/2021/02/19/github-secrets-java.html