# media-cloud-sync/1.2.10/includes/sdk/s3/Aws/Crypto/Cipher/CipherBuilderTrait.php

Media Cloud Sync, version 1.2.10. 67 lines.

- Page: https://pluginprobe.com/plugins/media-cloud-sync/1.2.10/code/includes/sdk/s3/Aws/Crypto/Cipher/CipherBuilderTrait.php
- Raw: https://pluginprobe.com/plugins/media-cloud-sync/1.2.10/raw/includes/sdk/s3/Aws/Crypto/Cipher/CipherBuilderTrait.php
- Modified: 2024-10-27T10:40:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/media-cloud-sync/1.2.10/code/includes/sdk/s3/Aws/Crypto/Cipher/CipherBuilderTrait.php#L10-L20`.

```php
<?php

namespace Dudlewebs\WPMCS\s3\Aws\Crypto\Cipher;

use Dudlewebs\WPMCS\s3\Aws\Exception\CryptoException;
trait CipherBuilderTrait
{
    /**
     * Returns an identifier recognizable by `openssl_*` functions, such as
     * `aes-256-cbc` or `aes-128-ctr`.
     *
     * @param string $cipherName Name of the cipher being used for encrypting
     *                           or decrypting.
     * @param int $keySize Size of the encryption key, in bits, that will be
     *                     used.
     *
     * @return string
     */
    protected function getCipherOpenSslName($cipherName, $keySize)
    {
        return "aes-{$keySize}-{$cipherName}";
    }
    /**
     * Constructs a CipherMethod for the given name, initialized with the other
     * data passed for use in encrypting or decrypting.
     *
     * @param string $cipherName Name of the cipher to generate for encrypting.
     * @param string $iv Base Initialization Vector for the cipher.
     * @param int $keySize Size of the encryption key, in bits, that will be
     *                     used.
     *
     * @return CipherMethod
     *
     * @internal
     */
    protected function buildCipherMethod($cipherName, $iv, $keySize)
    {
        switch ($cipherName) {
            case 'cbc':
                return new Cbc($iv, $keySize);
            default:
                return null;
        }
    }
    /**
     * Performs a reverse lookup to get the openssl_* cipher name from the
     * AESName passed in from the MetadataEnvelope.
     *
     * @param $aesName
     *
     * @return string
     *
     * @internal
     */
    protected function getCipherFromAesName($aesName)
    {
        switch ($aesName) {
            case 'AES/GCM/NoPadding':
                return 'gcm';
            case 'AES/CBC/PKCS5Padding':
                return 'cbc';
            default:
                throw new CryptoException('Unrecognized or unsupported' . ' AESName for reverse lookup.');
        }
    }
}

```
