Go lang 3DES partially decrypted the encrypted string












0















While performing decryption using 3des the given encrypted text is not fully decrypted, not sure where it went wrong, help me complete the decryption error



The code is avaialbe at Go Playground for Insection and run



package main

import (
"crypto/des"
"encoding/hex"
"fmt"
)

func main() {

// Mimimum Key Size of Length 24
key := "mysecretPasswordkeySiz24"
plainText := "https://8gwifi.org"
ct := EncryptTripleDES(byte(key),plainText)
fmt.Printf("Original Text: %sn",plainText)
fmt.Printf("3DES Encrypted Text: %sn", ct)
DecryptTripleDES(byte(key),ct)

}

func EncryptTripleDES(key byte, plaintext string) string {
c,err := des.NewTripleDESCipher(key)
if err != nil {
fmt.Errorf("NewTripleDESCipher(%d bytes) = %s", len(key), err)
panic(err)
}

out := make(byte, len(plaintext))
c.Encrypt(out, byte(plaintext))
return hex.EncodeToString(out)

}


func DecryptTripleDES(key byte, ct string) {

ciphertext, _ := hex.DecodeString(ct)
c, err := des.NewTripleDESCipher(byte(key))
if err != nil {
fmt.Errorf("NewTripleDESCipher(%d bytes) = %s", len(key), err)
panic(err)
}
plain := make(byte, len(ciphertext))
c.Decrypt(plain, ciphertext)
s := string(plain[:])
fmt.Printf("3DES Decrypyed Text: %sn", s)
}


The output



Original Text:  https://8gwifi.org
3DES Encrypted Text: a6e5215154bf86d000000000000000000000
3DES Decrypyed Text: https://









share|improve this question



























    0















    While performing decryption using 3des the given encrypted text is not fully decrypted, not sure where it went wrong, help me complete the decryption error



    The code is avaialbe at Go Playground for Insection and run



    package main

    import (
    "crypto/des"
    "encoding/hex"
    "fmt"
    )

    func main() {

    // Mimimum Key Size of Length 24
    key := "mysecretPasswordkeySiz24"
    plainText := "https://8gwifi.org"
    ct := EncryptTripleDES(byte(key),plainText)
    fmt.Printf("Original Text: %sn",plainText)
    fmt.Printf("3DES Encrypted Text: %sn", ct)
    DecryptTripleDES(byte(key),ct)

    }

    func EncryptTripleDES(key byte, plaintext string) string {
    c,err := des.NewTripleDESCipher(key)
    if err != nil {
    fmt.Errorf("NewTripleDESCipher(%d bytes) = %s", len(key), err)
    panic(err)
    }

    out := make(byte, len(plaintext))
    c.Encrypt(out, byte(plaintext))
    return hex.EncodeToString(out)

    }


    func DecryptTripleDES(key byte, ct string) {

    ciphertext, _ := hex.DecodeString(ct)
    c, err := des.NewTripleDESCipher(byte(key))
    if err != nil {
    fmt.Errorf("NewTripleDESCipher(%d bytes) = %s", len(key), err)
    panic(err)
    }
    plain := make(byte, len(ciphertext))
    c.Decrypt(plain, ciphertext)
    s := string(plain[:])
    fmt.Printf("3DES Decrypyed Text: %sn", s)
    }


    The output



    Original Text:  https://8gwifi.org
    3DES Encrypted Text: a6e5215154bf86d000000000000000000000
    3DES Decrypyed Text: https://









    share|improve this question

























      0












      0








      0








      While performing decryption using 3des the given encrypted text is not fully decrypted, not sure where it went wrong, help me complete the decryption error



      The code is avaialbe at Go Playground for Insection and run



      package main

      import (
      "crypto/des"
      "encoding/hex"
      "fmt"
      )

      func main() {

      // Mimimum Key Size of Length 24
      key := "mysecretPasswordkeySiz24"
      plainText := "https://8gwifi.org"
      ct := EncryptTripleDES(byte(key),plainText)
      fmt.Printf("Original Text: %sn",plainText)
      fmt.Printf("3DES Encrypted Text: %sn", ct)
      DecryptTripleDES(byte(key),ct)

      }

      func EncryptTripleDES(key byte, plaintext string) string {
      c,err := des.NewTripleDESCipher(key)
      if err != nil {
      fmt.Errorf("NewTripleDESCipher(%d bytes) = %s", len(key), err)
      panic(err)
      }

      out := make(byte, len(plaintext))
      c.Encrypt(out, byte(plaintext))
      return hex.EncodeToString(out)

      }


      func DecryptTripleDES(key byte, ct string) {

      ciphertext, _ := hex.DecodeString(ct)
      c, err := des.NewTripleDESCipher(byte(key))
      if err != nil {
      fmt.Errorf("NewTripleDESCipher(%d bytes) = %s", len(key), err)
      panic(err)
      }
      plain := make(byte, len(ciphertext))
      c.Decrypt(plain, ciphertext)
      s := string(plain[:])
      fmt.Printf("3DES Decrypyed Text: %sn", s)
      }


      The output



      Original Text:  https://8gwifi.org
      3DES Encrypted Text: a6e5215154bf86d000000000000000000000
      3DES Decrypyed Text: https://









      share|improve this question














      While performing decryption using 3des the given encrypted text is not fully decrypted, not sure where it went wrong, help me complete the decryption error



      The code is avaialbe at Go Playground for Insection and run



      package main

      import (
      "crypto/des"
      "encoding/hex"
      "fmt"
      )

      func main() {

      // Mimimum Key Size of Length 24
      key := "mysecretPasswordkeySiz24"
      plainText := "https://8gwifi.org"
      ct := EncryptTripleDES(byte(key),plainText)
      fmt.Printf("Original Text: %sn",plainText)
      fmt.Printf("3DES Encrypted Text: %sn", ct)
      DecryptTripleDES(byte(key),ct)

      }

      func EncryptTripleDES(key byte, plaintext string) string {
      c,err := des.NewTripleDESCipher(key)
      if err != nil {
      fmt.Errorf("NewTripleDESCipher(%d bytes) = %s", len(key), err)
      panic(err)
      }

      out := make(byte, len(plaintext))
      c.Encrypt(out, byte(plaintext))
      return hex.EncodeToString(out)

      }


      func DecryptTripleDES(key byte, ct string) {

      ciphertext, _ := hex.DecodeString(ct)
      c, err := des.NewTripleDESCipher(byte(key))
      if err != nil {
      fmt.Errorf("NewTripleDESCipher(%d bytes) = %s", len(key), err)
      panic(err)
      }
      plain := make(byte, len(ciphertext))
      c.Decrypt(plain, ciphertext)
      s := string(plain[:])
      fmt.Printf("3DES Decrypyed Text: %sn", s)
      }


      The output



      Original Text:  https://8gwifi.org
      3DES Encrypted Text: a6e5215154bf86d000000000000000000000
      3DES Decrypyed Text: https://






      go encryption des 3des






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 5:52









      anishanish

      2,87384191




      2,87384191
























          1 Answer
          1






          active

          oldest

          votes


















          2















          the given encrypted text is not fully decrypted




          The encrypted text you gave is fully decrypted. The problem is not (yet) the decryption but your encryption. As documented des.NewTripleDESCipher returns a cipher.Block and cipher.Block.Encrypt encrypts as documented only the first block of the input data. Given that DES has a block size of 8 byte only the first 8 byte of the input data are encrypted, i.e. https://.



          This means in order to encrypt all data you must encrypt all blocks. Similar you need to decrypt all blocks when decrypting - but cipher.Block.Decrypt also decrypts only a single block.



          Apart from that DES is broken, so don't use it for something serious.






          share|improve this answer
























          • This Make sense, yep not using DES but relying on 3des

            – anish
            Nov 16 '18 at 7:06






          • 1





            @anish: Even 3DES is not really recommended anymore.

            – Steffen Ullrich
            Nov 16 '18 at 7:10














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332164%2fgo-lang-3des-partially-decrypted-the-encrypted-string%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2















          the given encrypted text is not fully decrypted




          The encrypted text you gave is fully decrypted. The problem is not (yet) the decryption but your encryption. As documented des.NewTripleDESCipher returns a cipher.Block and cipher.Block.Encrypt encrypts as documented only the first block of the input data. Given that DES has a block size of 8 byte only the first 8 byte of the input data are encrypted, i.e. https://.



          This means in order to encrypt all data you must encrypt all blocks. Similar you need to decrypt all blocks when decrypting - but cipher.Block.Decrypt also decrypts only a single block.



          Apart from that DES is broken, so don't use it for something serious.






          share|improve this answer
























          • This Make sense, yep not using DES but relying on 3des

            – anish
            Nov 16 '18 at 7:06






          • 1





            @anish: Even 3DES is not really recommended anymore.

            – Steffen Ullrich
            Nov 16 '18 at 7:10


















          2















          the given encrypted text is not fully decrypted




          The encrypted text you gave is fully decrypted. The problem is not (yet) the decryption but your encryption. As documented des.NewTripleDESCipher returns a cipher.Block and cipher.Block.Encrypt encrypts as documented only the first block of the input data. Given that DES has a block size of 8 byte only the first 8 byte of the input data are encrypted, i.e. https://.



          This means in order to encrypt all data you must encrypt all blocks. Similar you need to decrypt all blocks when decrypting - but cipher.Block.Decrypt also decrypts only a single block.



          Apart from that DES is broken, so don't use it for something serious.






          share|improve this answer
























          • This Make sense, yep not using DES but relying on 3des

            – anish
            Nov 16 '18 at 7:06






          • 1





            @anish: Even 3DES is not really recommended anymore.

            – Steffen Ullrich
            Nov 16 '18 at 7:10
















          2












          2








          2








          the given encrypted text is not fully decrypted




          The encrypted text you gave is fully decrypted. The problem is not (yet) the decryption but your encryption. As documented des.NewTripleDESCipher returns a cipher.Block and cipher.Block.Encrypt encrypts as documented only the first block of the input data. Given that DES has a block size of 8 byte only the first 8 byte of the input data are encrypted, i.e. https://.



          This means in order to encrypt all data you must encrypt all blocks. Similar you need to decrypt all blocks when decrypting - but cipher.Block.Decrypt also decrypts only a single block.



          Apart from that DES is broken, so don't use it for something serious.






          share|improve this answer














          the given encrypted text is not fully decrypted




          The encrypted text you gave is fully decrypted. The problem is not (yet) the decryption but your encryption. As documented des.NewTripleDESCipher returns a cipher.Block and cipher.Block.Encrypt encrypts as documented only the first block of the input data. Given that DES has a block size of 8 byte only the first 8 byte of the input data are encrypted, i.e. https://.



          This means in order to encrypt all data you must encrypt all blocks. Similar you need to decrypt all blocks when decrypting - but cipher.Block.Decrypt also decrypts only a single block.



          Apart from that DES is broken, so don't use it for something serious.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 6:02









          Steffen UllrichSteffen Ullrich

          62.5k360102




          62.5k360102













          • This Make sense, yep not using DES but relying on 3des

            – anish
            Nov 16 '18 at 7:06






          • 1





            @anish: Even 3DES is not really recommended anymore.

            – Steffen Ullrich
            Nov 16 '18 at 7:10





















          • This Make sense, yep not using DES but relying on 3des

            – anish
            Nov 16 '18 at 7:06






          • 1





            @anish: Even 3DES is not really recommended anymore.

            – Steffen Ullrich
            Nov 16 '18 at 7:10



















          This Make sense, yep not using DES but relying on 3des

          – anish
          Nov 16 '18 at 7:06





          This Make sense, yep not using DES but relying on 3des

          – anish
          Nov 16 '18 at 7:06




          1




          1





          @anish: Even 3DES is not really recommended anymore.

          – Steffen Ullrich
          Nov 16 '18 at 7:10







          @anish: Even 3DES is not really recommended anymore.

          – Steffen Ullrich
          Nov 16 '18 at 7:10






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332164%2fgo-lang-3des-partially-decrypted-the-encrypted-string%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          The Sandy Post

          Danny Elfman

          Pages that link to "Head v. Amoskeag Manufacturing Co."