CopyWithNewPassword() public static method

Return a copy of the passed in secret key, encrypted using a new password and the passed in algorithm.
public static CopyWithNewPassword ( PgpSecretKey key, char oldPassPhrase, char newPassPhrase, SymmetricKeyAlgorithmTag newEncAlgorithm, SecureRandom rand ) : PgpSecretKey
key PgpSecretKey The PgpSecretKey to be copied.
oldPassPhrase char The current password for the key.
newPassPhrase char The new password for the key.
newEncAlgorithm SymmetricKeyAlgorithmTag The algorithm to be used for the encryption.
rand Org.BouncyCastle.Security.SecureRandom Source of randomness.
return PgpSecretKey
示例#1
0
 public static PgpSecretKeyRing CopyWithNewPassword(PgpSecretKeyRing ring, char[] oldPassPhrase, char[] newPassPhrase, SymmetricKeyAlgorithmTag newEncAlgorithm, SecureRandom rand)
 {
     global::System.Collections.IList       list       = Platform.CreateArrayList(((global::System.Collections.ICollection)ring.keys).get_Count());
     global::System.Collections.IEnumerator enumerator = ring.GetSecretKeys().GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             PgpSecretKey pgpSecretKey = (PgpSecretKey)enumerator.get_Current();
             if (pgpSecretKey.IsPrivateKeyEmpty)
             {
                 list.Add((object)pgpSecretKey);
             }
             else
             {
                 list.Add((object)PgpSecretKey.CopyWithNewPassword(pgpSecretKey, oldPassPhrase, newPassPhrase, newEncAlgorithm, rand));
             }
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(new PgpSecretKeyRing(list, ring.extraPubKeys));
 }
示例#2
0
        /// <summary>
        /// Return a copy of the passed in secret key ring, with the master key and sub keys encrypted
        /// using a new password and the passed in algorithm.
        /// </summary>
        /// <param name="ring">The <c>PgpSecretKeyRing</c> to be copied.</param>
        /// <param name="oldPassPhrase">The current password for key.</param>
        /// <param name="newPassPhrase">The new password for the key.</param>
        /// <param name="newEncAlgorithm">The algorithm to be used for the encryption.</param>
        /// <param name="rand">Source of randomness.</param>
        public static PgpSecretKeyRing CopyWithNewPassword(
            PgpSecretKeyRing ring,
            char[]                                          oldPassPhrase,
            char[]                                          newPassPhrase,
            SymmetricKeyAlgorithmTag newEncAlgorithm,
            SecureRandom rand)
        {
            IList newKeys = Platform.CreateArrayList(ring.keys.Count);

            foreach (PgpSecretKey secretKey in ring.GetSecretKeys())
            {
                newKeys.Add(PgpSecretKey.CopyWithNewPassword(secretKey, oldPassPhrase, newPassPhrase, newEncAlgorithm, rand));
            }

            return(new PgpSecretKeyRing(newKeys, ring.extraPubKeys));
        }