github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/docs/content/functions/crypto.md (about)

     1  ---
     2  title: crypto functions
     3  menu:
     4    main:
     5      parent: functions
     6  ---
     7  
     8  A set of crypto-related functions to be able to perform hashing and (simple!)
     9  encryption operations with `gomplate`.
    10  
    11  _Note: These functions are mostly wrappers of existing functions in the Go
    12  standard library. The authors of gomplate are not cryptographic experts,
    13  however, and so can not guarantee correctness of implementation. It is
    14  recommended to have your resident security experts inspect gomplate's code
    15  before using gomplate for critical security infrastructure!_
    16  
    17  ## `crypto.Bcrypt`
    18  
    19  Uses the [bcrypt](https://en.wikipedia.org/wiki/Bcrypt) password hashing algorithm to generate the hash of a given string. Wraps the [`golang.org/x/crypto/brypt`](https://godoc.org/golang.org/x/crypto/bcrypt) package.
    20  
    21  _Added in gomplate [v2.6.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.6.0)_
    22  ### Usage
    23  
    24  ```
    25  crypto.Bcrypt [cost] input
    26  ```
    27  ```
    28  input | crypto.Bcrypt [cost]
    29  ```
    30  
    31  ### Arguments
    32  
    33  | name | description |
    34  |------|-------------|
    35  | `cost` | _(optional)_ the cost, as a number from `4` to `31` - defaults to `10` |
    36  | `input` | _(required)_ the input to hash, usually a password |
    37  
    38  ### Examples
    39  
    40  ```console
    41  $ gomplate -i '{{ "foo" | crypto.Bcrypt }}'
    42  $2a$10$jO8nKZ1etGkKK7I3.vPti.fYDAiBqwazQZLUhaFoMN7MaLhTP0SLy
    43  ```
    44  ```console
    45  $ gomplate -i '{{ crypto.Bcrypt 4 "foo" }}
    46  $2a$04$zjba3N38sjyYsw0Y7IRCme1H4gD0MJxH8Ixai0/sgsrf7s1MFUK1C
    47  ```
    48  
    49  ## `crypto.DecryptAES` _(experimental)_
    50  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
    51  
    52  [experimental]: ../config/#experimental
    53  
    54  Decrypts the given input using the given key. By default,
    55  uses AES-256-CBC, but supports 128- and 192-bit keys as well.
    56  
    57  This function prints the output as a string. Note that this may result in
    58  unreadable text if the decrypted payload is binary. See
    59  [`crypto.DecryptAESBytes`](#crypto.DecryptAESBytes) for another method.
    60  
    61  This function is suitable for decrypting data that was encrypted by
    62  Helm's `encryptAES` function, when the input is base64-decoded, and when
    63  using 256-bit keys.
    64  
    65  _Added in gomplate [v3.11.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.11.0)_
    66  ### Usage
    67  
    68  ```
    69  crypto.DecryptAES key [keyBits] input
    70  ```
    71  ```
    72  input | crypto.DecryptAES key [keyBits]
    73  ```
    74  
    75  ### Arguments
    76  
    77  | name | description |
    78  |------|-------------|
    79  | `key` | _(required)_ the key to use for decryption |
    80  | `keyBits` | _(optional)_ the key length to use - defaults to `256` |
    81  | `input` | _(required)_ the input to decrypt |
    82  
    83  ### Examples
    84  
    85  ```console
    86  $ gomplate -i '{{ base64.Decode "Gp2WG/fKOUsVlhcpr3oqgR+fRUNBcO1eZJ9CW+gDI18=" | crypto.DecryptAES "swordfish" 128 }}'
    87  hello world
    88  ```
    89  
    90  ## `crypto.DecryptAESBytes` _(experimental)_
    91  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
    92  
    93  [experimental]: ../config/#experimental
    94  
    95  Decrypts the given input using the given key. By default,
    96  uses AES-256-CBC, but supports 128- and 192-bit keys as well.
    97  
    98  This function outputs the raw byte array, which may be sent as input to
    99  other functions.
   100  
   101  This function is suitable for decrypting data that was encrypted by
   102  Helm's `encryptAES` function, when the input is base64-decoded, and when
   103  using 256-bit keys.
   104  
   105  _Added in gomplate [v3.11.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.11.0)_
   106  ### Usage
   107  
   108  ```
   109  crypto.DecryptAESBytes key [keyBits] input
   110  ```
   111  ```
   112  input | crypto.DecryptAESBytes key [keyBits]
   113  ```
   114  
   115  ### Arguments
   116  
   117  | name | description |
   118  |------|-------------|
   119  | `key` | _(required)_ the key to use for decryption |
   120  | `keyBits` | _(optional)_ the key length to use - defaults to `256` |
   121  | `input` | _(required)_ the input to decrypt |
   122  
   123  ### Examples
   124  
   125  ```console
   126  $ gomplate -i '{{ base64.Decode "Gp2WG/fKOUsVlhcpr3oqgR+fRUNBcO1eZJ9CW+gDI18=" | crypto.DecryptAES "swordfish" 128 }}'
   127  hello world
   128  ```
   129  
   130  ## `crypto.EncryptAES` _(experimental)_
   131  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   132  
   133  [experimental]: ../config/#experimental
   134  
   135  Encrypts the given input using the given key. By default,
   136  uses AES-256-CBC, but supports 128- and 192-bit keys as well.
   137  
   138  This function is suitable for encrypting data that will be decrypted by
   139  Helm's `decryptAES` function, when the output is base64-encoded, and when
   140  using 256-bit keys.
   141  
   142  _Added in gomplate [v3.11.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.11.0)_
   143  ### Usage
   144  
   145  ```
   146  crypto.EncryptAES key [keyBits] input
   147  ```
   148  ```
   149  input | crypto.EncryptAES key [keyBits]
   150  ```
   151  
   152  ### Arguments
   153  
   154  | name | description |
   155  |------|-------------|
   156  | `key` | _(required)_ the key to use for encryption |
   157  | `keyBits` | _(optional)_ the key length to use - defaults to `256` |
   158  | `input` | _(required)_ the input to encrypt |
   159  
   160  ### Examples
   161  
   162  ```console
   163  $ gomplate -i '{{ "hello world" | crypto.EncryptAES "swordfish" 128 | base64.Encode }}'
   164  MnRutHovsh/9JN3YrJtBVjZtI6xXZh33bCQS2iZ4SDI=
   165  ```
   166  
   167  ## `crypto.ECDSAGenerateKey` _(experimental)_
   168  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   169  
   170  [experimental]: ../config/#experimental
   171  
   172  Generate a new Elliptic Curve Private Key and output in
   173  PEM-encoded PKCS#1 ASN.1 DER form.
   174  
   175  Go's standard NIST P-224, P-256, P-384, and P-521 elliptic curves are all
   176  supported.
   177  
   178  Default curve is P-256 and can be overridden with the optional `curve`
   179  parameter.
   180  
   181  _Added in gomplate [v3.11.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.11.0)_
   182  ### Usage
   183  
   184  ```
   185  crypto.ECDSAGenerateKey [curve]
   186  ```
   187  ```
   188  curve | crypto.ECDSAGenerateKey
   189  ```
   190  
   191  ### Arguments
   192  
   193  | name | description |
   194  |------|-------------|
   195  | `curve` | _(optional)_ One of Go's standard NIST curves, P-224, P-256, P-384, or P-521 -
   196  defaults to P-256.
   197   |
   198  
   199  ### Examples
   200  
   201  ```console
   202  $ gomplate -i '{{ crypto.ECDSAGenerateKey }}'
   203  -----BEGIN EC PRIVATE KEY-----
   204  ...
   205  ```
   206  
   207  ## `crypto.ECDSADerivePublicKey` _(experimental)_
   208  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   209  
   210  [experimental]: ../config/#experimental
   211  
   212  Derive a public key from an elliptic curve private key and output in PKIX
   213  ASN.1 DER form.
   214  
   215  _Added in gomplate [v3.11.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.11.0)_
   216  ### Usage
   217  
   218  ```
   219  crypto.ECDSADerivePublicKey key
   220  ```
   221  ```
   222  key | crypto.ECDSADerivePublicKey
   223  ```
   224  
   225  ### Arguments
   226  
   227  | name | description |
   228  |------|-------------|
   229  | `key` | _(required)_ the private key to derive a public key from |
   230  
   231  ### Examples
   232  
   233  ```console
   234  $ gomplate -i '{{ crypto.ECDSAGenerateKey | crypto.ECDSADerivePublicKey }}'
   235  -----BEGIN PUBLIC KEY-----
   236  ...
   237  ```
   238  ```console
   239  $ gomplate -d key=priv.pem -i '{{ crypto.ECDSADerivePublicKey (include "key") }}'
   240  -----BEGIN PUBLIC KEY-----
   241  MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBZvTS1wcCJSsGYQUVoSVctynkuhke
   242  kikB38iNwx/80jzdm+Z8OmRGlwH6OE9NX1MyxjvYMimhcj6zkaOKh1/HhMABrfuY
   243  +hIz6+EUt/Db51awO7iCuRly5L4TZ+CnMAsIbtUOqsqwSQDtv0AclAuogmCst75o
   244  aztsmrD79OXXnhUlURI=
   245  -----END PUBLIC KEY-----
   246  ```
   247  
   248  ## `crypto.Ed25519GenerateKey`_(unreleased)_ _(experimental)_
   249  **Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
   250  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   251  
   252  [experimental]: ../config/#experimental
   253  
   254  Generate a new Ed25519 Private Key and output in
   255  PEM-encoded PKCS#8 ASN.1 DER form.
   256  
   257  ### Usage
   258  
   259  ```
   260  crypto.Ed25519GenerateKey
   261  ```
   262  
   263  
   264  ### Examples
   265  
   266  ```console
   267  $ gomplate -i '{{ crypto.Ed25519GenerateKey }}'
   268  -----BEGIN PRIVATE KEY-----
   269  ...
   270  ```
   271  
   272  ## `crypto.Ed25519GenerateKeyFromSeed`_(unreleased)_ _(experimental)_
   273  **Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
   274  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   275  
   276  [experimental]: ../config/#experimental
   277  
   278  Generate a new Ed25519 Private Key from a random seed and output in
   279  PEM-encoded PKCS#8 ASN.1 DER form.
   280  
   281  ### Usage
   282  
   283  ```
   284  crypto.Ed25519GenerateKeyFromSeed encoding seed
   285  ```
   286  ```
   287  seed | crypto.Ed25519GenerateKeyFromSeed encoding
   288  ```
   289  
   290  ### Arguments
   291  
   292  | name | description |
   293  |------|-------------|
   294  | `encoding` | _(required)_ the encoding that the seed is in (`hex` or `base64`) |
   295  | `seed` | _(required)_ the random seed encoded in either base64 or hex |
   296  
   297  ### Examples
   298  
   299  ```console
   300  $ gomplate -i '{{ crypto.Ed25519GenerateKeyFromSeed "base64" "MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA=" }}'
   301  -----BEGIN PRIVATE KEY-----
   302  ...
   303  ```
   304  
   305  ## `crypto.Ed25519DerivePublicKey`_(unreleased)_ _(experimental)_
   306  **Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
   307  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   308  
   309  [experimental]: ../config/#experimental
   310  
   311  Derive a public key from an Ed25519 private key and output in PKIX
   312  ASN.1 DER form.
   313  
   314  ### Usage
   315  
   316  ```
   317  crypto.Ed25519DerivePublicKey key
   318  ```
   319  ```
   320  key | crypto.Ed25519DerivePublicKey
   321  ```
   322  
   323  ### Arguments
   324  
   325  | name | description |
   326  |------|-------------|
   327  | `key` | _(required)_ the private key to derive a public key from |
   328  
   329  ### Examples
   330  
   331  ```console
   332  $ gomplate -i '{{ crypto.Ed25519GenerateKey | crypto.Ed25519DerivePublicKey }}'
   333  -----BEGIN PUBLIC KEY-----
   334  ...
   335  ```
   336  ```console
   337  $ gomplate -d key=priv.pem -i '{{ crypto.Ed25519DerivePublicKey (include "key") }}'
   338  -----BEGIN PUBLIC KEY-----
   339  ...PK
   340  ```
   341  
   342  ## `crypto.PBKDF2`
   343  
   344  Run the Password-Based Key Derivation Function #2 as defined in
   345  [RFC 8018 (PKCS #5 v2.1)](https://tools.ietf.org/html/rfc8018#section-5.2).
   346  
   347  This function outputs the binary result as a hexadecimal string.
   348  
   349  _Added in gomplate [v2.3.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.3.0)_
   350  ### Usage
   351  
   352  ```
   353  crypto.PBKDF2 password salt iter keylen [hashfunc]
   354  ```
   355  
   356  ### Arguments
   357  
   358  | name | description |
   359  |------|-------------|
   360  | `password` | _(required)_ the password to use to derive the key |
   361  | `salt` | _(required)_ the salt |
   362  | `iter` | _(required)_ iteration count |
   363  | `keylen` | _(required)_ desired length of derived key |
   364  | `hashfunc` | _(optional)_ the hash function to use - must be one of the allowed functions (either in the SHA-1 or SHA-2 sets). Defaults to `SHA-1` |
   365  
   366  ### Examples
   367  
   368  ```console
   369  $ gomplate -i '{{ crypto.PBKDF2 "foo" "bar" 1024 8 }}'
   370  32c4907c3c80792b
   371  ```
   372  
   373  ## `crypto.RSADecrypt` _(experimental)_
   374  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   375  
   376  [experimental]: ../config/#experimental
   377  
   378  Decrypt an RSA-encrypted input and print the output as a string. Note that
   379  this may result in unreadable text if the decrypted payload is binary. See
   380  [`crypto.RSADecryptBytes`](#crypto.RSADecryptBytes) for a safer method.
   381  
   382  The private key must be a PEM-encoded RSA private key in PKCS#1, ASN.1 DER
   383  form, which typically begins with `-----BEGIN RSA PRIVATE KEY-----`.
   384  
   385  The input text must be plain ciphertext, as a byte array, or safely
   386  convertible to a byte array. To decrypt base64-encoded input, you must
   387  first decode with the [`base64.DecodeBytes`](../base64/#base64.DecodeBytes)
   388  function.
   389  
   390  _Added in gomplate [v3.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.8.0)_
   391  ### Usage
   392  
   393  ```
   394  crypto.RSADecrypt key input
   395  ```
   396  ```
   397  input | crypto.RSADecrypt key
   398  ```
   399  
   400  ### Arguments
   401  
   402  | name | description |
   403  |------|-------------|
   404  | `key` | _(required)_ the private key to decrypt the input with |
   405  | `input` | _(required)_ the encrypted input |
   406  
   407  ### Examples
   408  
   409  ```console
   410  $ gomplate -c pubKey=./testPubKey -c privKey=./testPrivKey \
   411    -i '{{ $enc := "hello" | crypto.RSAEncrypt .pubKey -}}
   412    {{ crypto.RSADecrypt .privKey $enc }}'
   413  hello
   414  ```
   415  ```console
   416  $ export ENCRYPTED="ScTcX1NZ6p/EeDIf6R7FKLcDFjvP98YgiBhyhPE4jtehajIyTKP1GL8C72qbAWrgdQ6A2cSVjoyo3viqf/PZxpcBDUUMDJuemTaJqUUjMWaDuPG37mQbmRtcvFTuUhw1qSbKyHorDOgTX5d4DvWV4otycGtBT6dXhnmmb5V72J/w3z68vtTJ21m9wREFD7LrYVHdFFtRZiIyMBAF0ngQ+hcujrxilnmgzPkEAg6E7Ccctn28Ie2c4CojrwRbNNxXNlIWCCkC/8Vq8qlDfZ70a+BsTmJDuScE6BZbTyteo9uGYrLn+bTIHNDj90AeLCKUTyWLUJ5Edi9LhlKVBoJUNQ=="
   417  $ gomplate -c ciphertext=env:///ENCRYPTED -c privKey=./testPrivKey \
   418    -i '{{ base64.DecodeBytes .ciphertext | crypto.RSADecrypt .privKey }}'
   419  hello
   420  ```
   421  
   422  ## `crypto.RSADecryptBytes` _(experimental)_
   423  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   424  
   425  [experimental]: ../config/#experimental
   426  
   427  Decrypt an RSA-encrypted input and output the decrypted byte array.
   428  
   429  The private key must be a PEM-encoded RSA private key in PKCS#1, ASN.1 DER
   430  form, which typically begins with `-----BEGIN RSA PRIVATE KEY-----`.
   431  
   432  The input text must be plain ciphertext, as a byte array, or safely
   433  convertible to a byte array. To decrypt base64-encoded input, you must
   434  first decode with the [`base64.DecodeBytes`](../base64/#base64.DecodeBytes)
   435  function.
   436  
   437  See [`crypto.RSADecrypt`](#crypto.RSADecrypt) for a function that outputs
   438  a string.
   439  
   440  _Added in gomplate [v3.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.8.0)_
   441  ### Usage
   442  
   443  ```
   444  crypto.RSADecryptBytes key input
   445  ```
   446  ```
   447  input | crypto.RSADecryptBytes key
   448  ```
   449  
   450  ### Arguments
   451  
   452  | name | description |
   453  |------|-------------|
   454  | `key` | _(required)_ the private key to decrypt the input with |
   455  | `input` | _(required)_ the encrypted input |
   456  
   457  ### Examples
   458  
   459  ```console
   460  $ gomplate -c pubKey=./testPubKey -c privKey=./testPrivKey \
   461    -i '{{ $enc := "hello" | crypto.RSAEncrypt .pubKey -}}
   462    {{ crypto.RSADecryptBytes .privKey $enc }}'
   463  [104 101 108 108 111]
   464  ```
   465  ```console
   466  $ gomplate -c pubKey=./testPubKey -c privKey=./testPrivKey \
   467    -i '{{ $enc := "hello" | crypto.RSAEncrypt .pubKey -}}
   468    {{ crypto.RSADecryptBytes .privKey $enc | conv.ToString }}'
   469  hello
   470  ```
   471  
   472  ## `crypto.RSAEncrypt` _(experimental)_
   473  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   474  
   475  [experimental]: ../config/#experimental
   476  
   477  Encrypt the input with RSA and the padding scheme from PKCS#1 v1.5.
   478  
   479  This function is suitable for encrypting data that will be decrypted by
   480  [Terraform's `rsadecrypt` function](https://www.terraform.io/docs/configuration/functions/rsadecrypt.html).
   481  
   482  The key should be a PEM-encoded RSA public key in PKIX ASN.1 DER form,
   483  which typically begins with `BEGIN PUBLIC KEY`. RSA public keys in PKCS#1
   484  ASN.1 DER form are also supported (beginning with `RSA PUBLIC KEY`).
   485  
   486  The output will not be encoded, so consider
   487  [base64-encoding](../base64/#base64.Encode) it for display.
   488  
   489  _Note:_ Output encrypted with this function will _not_ be deterministic,
   490  so encrypting the same input twice will not result in the same ciphertext.
   491  
   492  _Warning:_ Using this function may not be safe. See the warning on Go's
   493  [`rsa.EncryptPKCS1v15`](https://golang.org/pkg/crypto/rsa/#EncryptPKCS1v15)
   494  documentation.
   495  
   496  _Added in gomplate [v3.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.8.0)_
   497  ### Usage
   498  
   499  ```
   500  crypto.RSAEncrypt key input
   501  ```
   502  ```
   503  input | crypto.RSAEncrypt key
   504  ```
   505  
   506  ### Arguments
   507  
   508  | name | description |
   509  |------|-------------|
   510  | `key` | _(required)_ the public key to encrypt the input with |
   511  | `input` | _(required)_ the encrypted input |
   512  
   513  ### Examples
   514  
   515  ```console
   516  $ gomplate -c pubKey=./testPubKey \
   517    -i '{{ "hello" | crypto.RSAEncrypt .pubKey | base64.Encode }}'
   518  ScTcX1NZ6p/EeDIf6R7FKLcDFjvP98YgiBhyhPE4jtehajIyTKP1GL8C72qbAWrgdQ6A2cSVjoyo3viqf/PZxpcBDUUMDJuemTaJqUUjMWaDuPG37mQbmRtcvFTuUhw1qSbKyHorDOgTX5d4DvWV4otycGtBT6dXhnmmb5V72J/w3z68vtTJ21m9wREFD7LrYVHdFFtRZiIyMBAF0ngQ+hcujrxilnmgzPkEAg6E7Ccctn28Ie2c4CojrwRbNNxXNlIWCCkC/8Vq8qlDfZ70a+BsTmJDuScE6BZbTyteo9uGYrLn+bTIHNDj90AeLCKUTyWLUJ5Edi9LhlKVBoJUNQ==
   519  ```
   520  ```console
   521  $ gomplate -c pubKey=./testPubKey \
   522    -i '{{ $enc := "hello" | crypto.RSAEncrypt .pubKey -}}
   523    Ciphertext in hex: {{ printf "%x" $enc }}'
   524  71729b87cccabb248b9e0e5173f0b12c01d9d2a0565bad18aef9d332ce984bde06acb8bb69334a01446f7f6430077f269e6fbf2ccacd972fe5856dd4719252ebddf599948d937d96ea41540dad291b868f6c0cf647dffdb5acb22cd33557f9a1ddd0ee6c1ad2bbafc910ba8f817b66ea0569afc06e5c7858fd9dc2638861fe7c97391b2f190e4c682b4aa2c9b0050081efe18b10aa8c2b2b5f5b68a42dcc06c9da35b37fca9b1509fddc940eb99f516a2e0195405bcb3993f0fa31bc038d53d2e7231dff08cc39448105ed2d0ac52d375cb543ca8a399f807cc5d007e2c44c69876d189667eee66361a393c4916826af77479382838cd4e004b8baa05636805a
   525  ```
   526  
   527  ## `crypto.RSAGenerateKey` _(experimental)_
   528  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   529  
   530  [experimental]: ../config/#experimental
   531  
   532  Generate a new RSA Private Key and output in PEM-encoded PKCS#1 ASN.1 DER
   533  form.
   534  
   535  Default key length is 4096 bits, which should be safe enough for most
   536  uses, but can be overridden with the optional `bits` parameter.
   537  
   538  In order to protect against [CWE-326](https://cwe.mitre.org/data/definitions/326.html),
   539  keys shorter than `2048` bits may not be generated.
   540  
   541  The output is a string, suitable for use with the other `crypto.RSA*`
   542  functions.
   543  
   544  _Added in gomplate [v3.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.8.0)_
   545  ### Usage
   546  
   547  ```
   548  crypto.RSAGenerateKey [bits]
   549  ```
   550  ```
   551  bits | crypto.RSAGenerateKey
   552  ```
   553  
   554  ### Arguments
   555  
   556  | name | description |
   557  |------|-------------|
   558  | `bits` | _(optional)_ Length in bits of the generated key. Must be at least `2048`. Defaults to `4096` |
   559  
   560  ### Examples
   561  
   562  ```console
   563  $ gomplate -i '{{ crypto.RSAGenerateKey }}'
   564  -----BEGIN RSA PRIVATE KEY-----
   565  ...
   566  ```
   567  ```console
   568  $ gomplate -i '{{ $key := crypto.RSAGenerateKey 2048 -}}
   569    {{ $pub := crypto.RSADerivePublicKey $key -}}
   570    {{ $enc := "hello" | crypto.RSAEncrypt $pub -}}
   571    {{ crypto.RSADecrypt $key $enc }}'
   572  hello
   573  ```
   574  
   575  ## `crypto.RSADerivePublicKey` _(experimental)_
   576  **Experimental:** This function is [_experimental_][experimental] and may be enabled with the [`--experimental`][experimental] flag.
   577  
   578  [experimental]: ../config/#experimental
   579  
   580  Derive a public key from an RSA private key and output in PKIX ASN.1 DER
   581  form.
   582  
   583  The output is a string, suitable for use with other `crypto.RSA*`
   584  functions.
   585  
   586  _Added in gomplate [v3.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.8.0)_
   587  ### Usage
   588  
   589  ```
   590  crypto.RSADerivePublicKey key
   591  ```
   592  ```
   593  key | crypto.RSADerivePublicKey
   594  ```
   595  
   596  ### Arguments
   597  
   598  | name | description |
   599  |------|-------------|
   600  | `key` | _(required)_ the private key to derive a public key from |
   601  
   602  ### Examples
   603  
   604  ```console
   605  $ gomplate -i '{{ crypto.RSAGenerateKey | crypto.RSADerivePublicKey }}'
   606  -----BEGIN PUBLIC KEY-----
   607  ...
   608  ```
   609  ```console
   610  $ gomplate -c privKey=./privKey.pem \
   611    -i '{{ $pub := crypto.RSADerivePublicKey .privKey -}}
   612    {{ $enc := "hello" | crypto.RSAEncrypt $pub -}}
   613    {{ crypto.RSADecrypt .privKey $enc }}'
   614  hello
   615  ```
   616  
   617  ## `crypto.SHA1`, `crypto.SHA224`, `crypto.SHA256`, `crypto.SHA384`, `crypto.SHA512`, `crypto.SHA512_224`, `crypto.SHA512_256`
   618  
   619  Compute a checksum with a SHA-1 or SHA-2 algorithm as defined in [RFC 3174](https://tools.ietf.org/html/rfc3174) (SHA-1) and [FIPS 180-4](http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) (SHA-2).
   620  
   621  These functions output the binary result as a hexadecimal string.
   622  
   623  _Warning: SHA-1 is cryptographically broken and should not be used for secure applications._
   624  
   625  _Added in gomplate [v2.3.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.3.0)_
   626  ### Usage
   627  ```
   628  crypto.SHA1 input
   629  crypto.SHA224 input
   630  crypto.SHA256 input
   631  crypto.SHA384 input
   632  crypto.SHA512 input
   633  crypto.SHA512_224 input
   634  crypto.SHA512_256 input
   635  ```
   636  
   637  ### Arguments
   638  
   639  | name | description |
   640  |------|-------------|
   641  | `input` | _(required)_ the data to hash - can be binary data or text |
   642  
   643  ### Examples
   644  
   645  ```console
   646  $ gomplate -i '{{ crypto.SHA1 "foo" }}'
   647  f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
   648  ```
   649  ```console
   650  $ gomplate -i '{{ crypto.SHA512 "bar" }}'
   651  cc06808cbbee0510331aa97974132e8dc296aeb795be229d064bae784b0a87a5cf4281d82e8c99271b75db2148f08a026c1a60ed9cabdb8cac6d24242dac4063
   652  ```
   653  
   654  ## `crypto.SHA1Bytes`, `crypto.SHA224Bytes`, `crypto.SHA256Bytes`, `crypto.SHA384Bytes`, `crypto.SHA512Bytes`, `crypto.SHA512_224Bytes`, `crypto.SHA512_256Bytes`
   655  
   656  Compute a checksum with a SHA-1 or SHA-2 algorithm as defined in [RFC 3174](https://tools.ietf.org/html/rfc3174) (SHA-1) and [FIPS 180-4](http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) (SHA-2).
   657  
   658  These functions output the raw binary result, suitable for piping to other functions.
   659  
   660  _Warning: SHA-1 is cryptographically broken and should not be used for secure applications._
   661  
   662  _Added in gomplate [v3.11.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.11.0)_
   663  ### Usage
   664  ```
   665  crypto.SHA1Bytes input
   666  crypto.SHA224Bytes input
   667  crypto.SHA256Bytes input
   668  crypto.SHA384Bytes input
   669  crypto.SHA512Bytes input
   670  crypto.SHA512_224Bytes input
   671  crypto.SHA512_256Bytes input
   672  ```
   673  
   674  ### Arguments
   675  
   676  | name | description |
   677  |------|-------------|
   678  | `input` | _(required)_ the data to hash - can be binary data or text |
   679  
   680  ### Examples
   681  
   682  ```console
   683  $ gomplate -i '{{ crypto.SHA256Bytes "foo" | base64.Encode }}'
   684  LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564=
   685  ```
   686  
   687  ## `crypto.WPAPSK`
   688  
   689  This is really an alias to [`crypto.PBKDF2`](#crypto.PBKDF2) with the
   690  values necessary to convert ASCII passphrases to the WPA pre-shared keys for use with WiFi networks.
   691  
   692  This can be used, for example, to help generate a configuration for [wpa_supplicant](http://w1.fi/wpa_supplicant/).
   693  
   694  _Added in gomplate [v2.3.0](https://github.com/hairyhenderson/gomplate/releases/tag/v2.3.0)_
   695  ### Usage
   696  
   697  ```
   698  crypto.WPAPSK ssid password
   699  ```
   700  
   701  ### Arguments
   702  
   703  | name | description |
   704  |------|-------------|
   705  | `ssid` | _(required)_ the WiFi SSID (network name) - must be less than 32 characters |
   706  | `password` | _(required)_ the password - must be between 8 and 63 characters |
   707  
   708  ### Examples
   709  
   710  ```console
   711  $ PW=abcd1234 gomplate -i '{{ crypto.WPAPSK "mynet" (getenv "PW") }}'
   712  2c201d66f01237d17d4a7788051191f31706844ac3ffe7547a66c902f2900d34
   713  ```