Encode a private key using a password

@param {string} privateKey - An hex private key
@param {string} password - A password

@return {object} - The encoded data
344099
function(privateKey, password) {
    // Errors
    if (!privateKey || !password) throw new Error('Missing argument !');
    if (!Helpers.isPrivateKeyValid(privateKey)) throw new Error('Private key is not valid !');
    // Processing
    let pass = derivePassSha(password, 20);
    let r = encrypt(privateKey, convert.hex2ua(pass.priv));
    // Result
    return {
        ciphertext: CryptoJS.enc.Hex.stringify(r.ciphertext),
        iv: convert.ua2hex(r.iv)
    };
}
198135
function encrypt(salt, password) {
    var hash = crypto.createHash('sha256').update(salt + password).digest('base64');
    return salt + hash;
}
1235835
def encode_password(password)
    i = 0
    chars = password.split(//)
    count = chars.size

    chars.collect! do |char|
      i += 1
      char     = char.ord << i
      low_15   = char & 0x7fff
      high_15  = char & 0x7fff << 15
      high_15  = high_15 >> 15
      char     = low_15 | high_15
    end

    encoded_password  = 0x0000
    chars.each { |c| encoded_password ^= c }
    encoded_password ^= count
    encoded_password ^= 0xCE4B
  end
1100560
function decryptJson(password, data) {
    var salt = new Buffer(data.salt, 'base64');
    return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then(function (key) {
        var iv = new Buffer(data.iv, 'base64');
        var decipher = crypto.createDecipheriv(cipherAlgorithm, key, iv);
        var tag = data.tag;
        if (tag) {
            decipher.setAuthTag(new Buffer(tag, 'base64'));
        }
        var value = decipher.update(data.value, 'base64', 'utf8');
        value += decipher.final('utf8');
        return value;
    }).then(JSON.parse);
}
405320
def encrypt(password)
      encoded_password = Base64.strict_encode64 "#{password}|#{time_stamp}"

      encrypted_password = public_key.public_encrypt encoded_password

      Base64.strict_encode64 encrypted_password
    end
696052
def decrypt_key(key, password):
    
    private = serialization.load_pem_private_key(key, password=password, backend=default_backend())
    return private.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption())
391171
def ed25519_private_key_to_string(key):
    
    return base64.b64encode(key.private_bytes(
        encoding=serialization.Encoding.Raw,
        format=serialization.PrivateFormat.Raw,
        encryption_algorithm=serialization.NoEncryption()
    ), None).decode('utf-8')
1273905
private static PrivateKey getPrivateKey(String filename, String password, String key) {
        if(logger.isDebugEnabled()) logger.debug("filename = " + filename + " key = " + key);
        PrivateKey privateKey = null;

        try {
            KeyStore keystore = KeyStore.getInstance("JKS");
            keystore.load(Config.getInstance().getInputStreamFromFile(filename),
                    password.toCharArray());

            privateKey = (PrivateKey) keystore.getKey(key,
                    password.toCharArray());
        } catch (Exception e) {
            logger.error("Exception:", e);
        }

        if (privateKey == null) {
            logger.error("Failed to retrieve private key from keystore");
        }

        return privateKey;
    }
1101538
function (password, salt) {
            // Shortcut
            var cfg = this.cfg;

            // Init HMAC
            var hmac = HMAC.create(cfg.hasher, password);

            // Initial values
            var derivedKey = WordArray.create();
            var blockIndex = WordArray.create([0x00000001]);

            // Shortcuts
            var derivedKeyWords = derivedKey.words;
            var blockIndexWords = blockIndex.words;
            var keySize = cfg.keySize;
            var iterations = cfg.iterations;

            // Generate key
            while (derivedKeyWords.length < keySize) {
                var block = hmac.update(salt).finalize(blockIndex);
                hmac.reset();

                // Shortcuts
                var blockWords = block.words;
                var blockWordsLength = blockWords.length;

                // Iterations
                var intermediate = block;
                for (var i = 1; i < iterations; i++) {
                    intermediate = hmac.finalize(intermediate);
                    hmac.reset();

                    // Shortcut
                    var intermediateWords = intermediate.words;

                    // XOR intermediate with block
                    for (var j = 0; j < blockWordsLength; j++) {
                        blockWords[j] ^= intermediateWords[j];
                    }
                }

                derivedKey.concat(block);
                blockIndexWords[0]++;
            }
            derivedKey.sigBytes = keySize * 4;

            return derivedKey;
        }
195919
function PairPrivateKey(keyData) {
  this.__key = (typeof keyData === 'object' ? keyData : null);
  this.__encoded = (typeof keyData === 'string' ? keyData : null);
}
179577
public static String encryptByPrivateKey(String data, String privateKey) throws Exception {
		PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(base64.decode(privateKey));
		KeyFactory keyf = KeyFactory.getInstance("RSA");
		PrivateKey priKey = keyf.generatePrivate(priPKCS8);
		java.security.Signature signature = java.security.Signature.getInstance("SHA256WithRSA");

		signature.initSign(priKey);
		signature.update(data.getBytes("UTf-8"));
		byte[] signed = signature.sign();
		return base64.encodeToString(signed);
	}
404129
function privKeyToPubKey(privKey, toCompressed) {
  toCompressed = toCompressed || false;

  const pkBuffer = Buffer.from(privKey, 'hex');
  var publicKey = secp256k1.publicKeyCreate(pkBuffer, toCompressed);
  return publicKey.toString('hex');
}
565807
public static String privateKey2String(PrivateKey key) {
        PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(key.getEncoded());
        return new String(Base64.getEncoder().encode(spec.getEncoded()), StandardCharsets.UTF_8);
    }
189524
def seal(token, context = nil)
      raise RuntimeError, "signing private key must be set" unless self.instance_variable_get(:@signing_private_key)
      binary_token = token.to_binary_s
      signature = self.encryptor.sign(binary_token, self.instance_variable_get(:@signing_private_key), self, context)
      Base64.strict_encode64([binary_token, signature].join)
    end
1120631
def import_private_key(self, pem_text, password=None):
		
		if isinstance(pem_text, str) is True:
			pem_text = pem_text.encode()
		if password is not None and isinstance(password, str) is True:
			password = password.encode()

		self.__set_private_key(
			serialization.load_pem_private_key(pem_text, password=password, backend=default_backend())
		)
1133757
public PrivateKey getPrivateKeyFromString(String key) throws MangooEncryptionException {
        Objects.requireNonNull(key, Required.KEY.toString());
        
        try {
            return KeyFactory.getInstance(ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(decodeBase64(key)));
        } catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
            throw new MangooEncryptionException("Failed to get private key from string", e);
        }
    }
1087985
def encode(password)
      primary = ::Digest::MD5.new
      primary << password
      primary << prefix
      primary << @salt

      md5_t = ::Digest::MD5.digest("#{password}#{@salt}#{password}")

      l = password.length
      while l > 0 do
        slice_size = ( l > DIGEST_LENGTH ) ? DIGEST_LENGTH : l
        primary << md5_t[0, slice_size]
        l -= DIGEST_LENGTH
      end

      # weirdness
      l = password.length
      while l != 0
        case (l & 1)
        when 1
          primary << 0.chr
        when 0
          primary << password[0,1]
        end
        l >>= 1
      end

      pd = primary.digest

      encoded_password = "#{prefix}#{@salt}$"

      # apr_md5_encode has this comment about a 60Mhz Pentium above this loop.
      1000.times do |x|
        ctx = ::Digest::MD5.new
        ctx << (( ( x & 1 ) == 1 ) ? password : pd[0,DIGEST_LENGTH])
        (ctx << @salt) unless ( x % 3 ) == 0
        (ctx << password) unless ( x % 7 ) == 0
        ctx << (( ( x & 1 ) == 0 ) ? password : pd[0,DIGEST_LENGTH])
        pd = ctx.digest
      end


      pd = pd.bytes.to_a

      l = (pd[ 0]<<16) | (pd[ 6]<<8) | pd[12]
      encoded_password << to_64(l, 4)

      l = (pd[ 1]<<16) | (pd[ 7]<<8) | pd[13]
      encoded_password << to_64(l, 4)

      l = (pd[ 2]<<16) | (pd[ 8]<<8) | pd[14]
      encoded_password << to_64(l, 4)

      l = (pd[ 3]<<16) | (pd[ 9]<<8) | pd[15]
      encoded_password << to_64(l, 4)

      l = (pd[ 4]<<16) | (pd[10]<<8) | pd[ 5]
      encoded_password << to_64(l, 4)
      encoded_password << to_64(pd[11],2)

      return encoded_password
    end