Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
System.Security.Cryptography.CryptographicException: The specified network password is not correct.

at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)


Error Give in Push Notification For Apple
Posted
Updated 20-Nov-13 19:58pm
v3

1 solution

The error message is pretty specific: "The specified network password is not correct."
So look at what your code is doing (and we have no idea because we can't see your screen) and find the network password you are using - you may have picked up the wrong value, or it may have been changed.

But we can't sort that out for you - you are going to have top look at your code around where the error occurs using the debugger.
 
Share this answer
 
Comments
sohal6789 21-Nov-13 2:00am    
int port = 2195;
String deviceID = "f9441df1e771248c17cc79f870c3e5b9ea9c83627b035fff1a7805e0026d339d";
String hostname = "gateway.sandbox.push.apple.com"; // TEST
//String hostname = "gateway.push.apple.com"; // REAL

// @"cert.p12";
String certificatePath = HttpContext.Current.Server.MapPath("certificate_push.p12");
//X509Certificate2 clientCertificate = new X509Certificate2(certificatePath, "");
// _certificate = string.IsNullOrEmpty(p12FilePassword) ? new X509Certificate2(File.ReadAllBytes(p12File)) : new X509Certificate2(File.ReadAllBytes(p12File), p12FilePassword, X509KeyStorageFlags.MachineKeySet);
// X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
X509Certificate2 clientCertificate= new X509Certificate2(certificatePath, "", X509KeyStorageFlags.MachineKeySet);
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
TcpClient client = new TcpClient(hostname, port);

// _apnsStream = new SslStream(_apnsClient.GetStream(), false, validateServerCertificate, SelectLocalCertificate);
// SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate),null);
// _certificate = string.IsNullOrEmpty("123456") ? new X509Certificate2(File.ReadAllBytes("certificate_push.p12")) : new X509Certificate2(File.ReadAllBytes("certificate_push.p12"), "123456", X509KeyStorageFlags.MachineKeySet);
SslStream sslStream = new SslStream(client.GetStream(), false, validateServerCertificate, SelectLocalCertificate);

try
{
sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Default, false);
}
catch (Exception e)
{
throw (e);
client.Close();

}

MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
writer.Write((byte)0); //The command
writer.Write((byte)0); //The first byte of the deviceId length (big-endian first byte)
writer.Write((byte)32); //The deviceId length (big-endian second byte)

writer.Write(HexStringToByteArray(deviceID.ToUpper()));
String payload = "{\"aps\":{\"alert\":\"hello\",\"badge\":0,\"sound\":\"default\"}}";
writer.Write((byte)0);
writer.Write((byte)payload.Length);
byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
writer.Write(b1);
writer.Flush();
byte[] array = memoryStream.ToArray();
sslStream.Write(array);
sslStream.Flush();
client.Close();
InsertActivityLog.Add(new AddActivityLog { MessageOutput = "Abc" });
JavaScriptSerializer js = new JavaScriptSerializer();
retJSON = js.Serialize(InsertActivityLog);
return retJSON;




thats my Code and give error in this
sohal6789 21-Nov-13 2:01am    
error
X509Certificate2 clientCertificate= new X509Certificate2(certificatePath, "", X509KeyStorageFlags.MachineKeySet);
at this line

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900