question

key-holder avatar image
key-holder asked

WebException: Error writing request: The authentication or decryption has failed.

I use Unity version 5.1.

The script for login. This works fine.

using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.AdminModels;
using System.IO;
using System;


public class UserLoginReg : MonoBehaviour {
	public InputField LoginEmailField;
	public InputField LoginPasswordField;
	public InputField RegUsernameField;
	public InputField RegEmailField;
	public InputField RegPasswordField;
	public InputField RegrePasswordField;
	public Popup popUp;
	public GameObject LoginButton;
	public GameObject LogoutButton;


	public Text statusText;


	private SaveData sd;
	private string PlayfabID = "C021";
	private Texture2D imgTexture;


	// Use this for initialization
	void Start () {
		sd = GameObject.Find("SaveAllData").GetComponent("SaveData") as SaveData;
		PlayFabSettings.TitleId = PlayfabID;
		imgTexture = new Texture2D(64, 64 , TextureFormat.ARGB32, false);
		Debug.Log (PlayfabID);


		if (sd.CustomAccountID == "") {
			LoginButton.SetActive (true);
			LogoutButton.SetActive (false);
		} else {
			LoginButton.SetActive (false);
			LogoutButton.SetActive (true);
		}
	}
	private void UpdateStatus(string status)
	{
		if (statusText != null)
		{
			statusText.text = String.Format("Status: {0}", status);
		}
	}


	//로그인
	public void Login()
	{
		PlayFabSettings.TitleId = PlayfabID;
		LoginWithEmailAddressRequest request = new LoginWithEmailAddressRequest()
		{
			TitleId = PlayfabID,
			Email = LoginEmailField.text,
			Password = LoginPasswordField.text


		};
		
		PlayFabClientAPI.LoginWithEmailAddress(request, (result) => {
			sd.CustomAccountID = result.PlayFabId;


			LoginButton.SetActive (false);
			LogoutButton.SetActive (true);


			//Debug.Log(PlayfabID + "Got PlayFabID: " + CustomAccountID);
			
			if(result.NewlyCreated)
			{
				Debug.Log("(new account)");
			}
			else
			{
				Debug.Log("(existing account)");
				sd.userImgFilename = "HoloFace"+sd.CustomAccountID+".png";
				sd.user_path = System.IO.Path.Combine(Application.persistentDataPath, sd.userImgFilename);


				if (!PlayerPrefs.HasKey ("HoloFace"+sd.CustomAccountID)) {
					sd.saveImage();
					PlayerPrefs.SetString ("HoloFace"+sd.CustomAccountID, "exist");


				} else {
					//UpdateStatus("HoloFace"+sd.CustomAccountID + " : "+PlayerPrefs.GetString ("HoloFace"+sd.CustomAccountID));
				}


				GetUserData();
				popUp.ShowPopup("Login");
				LoginEmailField.text="";
				LoginPasswordField.text="";
			}


		},
		(error) => {
			if(LoginEmailField.text.Length == 0){
				popUp.errorMessage("No ID");
			}else if(LoginPasswordField.text.Length <6){
				popUp.errorMessage("No PASS");
			}else{
				popUp.errorMessage(error.ErrorMessage.ToString());
			}


			popUp.ShowPopup("LoginFail");
		});
	}


	//로그아웃
	public void Logout(){
		sd.CustomAccountID = "";
        sd.resetData();


		LoginButton.SetActive (true);
		LogoutButton.SetActive (false);
		popUp.ShowPopup("Logout");
	}


The script for uploading files.

using UnityEngine;
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
using PlayFab;
using PlayFab.AdminModels;
using PlayFab.ClientModels;
using UnityEngine.UI;
using System;


public class ImgFileIO : MonoBehaviour {
	private SaveData sd;
	private string mimeType = "image/png"; // The MIME type that corresponds to the file above
	private string contentKey = "images/userImg.png"; // this is the location and 'identifier' for your uploaded file, you will need this key to access the file after uploading
	private bool isImageDownloaded = false;
	private bool isImageUploaded = false;
	public Texture2D downloadedImage;
	public Text statusText;


	void Start(){
		sd = GameObject.Find("SaveAllData").GetComponent("SaveData") as SaveData;
		this.downloadedImage = new Texture2D(0,0);
	}
	private void UpdateStatus(string status)
	{
		if (statusText != null)
		{
			statusText.text = String.Format("Status: {0}", status);
		}
	}
	public void resetContentKey(){
		//Sign judgment
		if (sd.CustomAccountID != "") {
			contentKey = "UserFace/"+sd.CustomAccountID+".png";
		}
	}


	public void userUploadImg(){
		try{
			resetContentKey();
			this.isImageUploaded = false;
			GetContentUploadURL();
		}catch(IOException e){
			//return false;
			UpdateStatus("UploadImg false");
		}
		UpdateStatus("UploadImg"+this.isImageUploaded+" : " + contentKey);
		//return this.isImageUploaded;
	}


	public void userDownloadImg(){
		resetContentKey();
		this.isImageDownloaded = false;
		GetContentDownloadURL();
		UpdateStatus ("DownloadImg"+this.isImageDownloaded + " : " + contentKey);
		//return downloadedImage;
	}


	void GetContentUploadURL()
	{
		GetContentUploadUrlRequest request = new GetContentUploadUrlRequest();
		
		request.Key = this.contentKey; // folder location & file name to use on the remote server
		request.ContentType = this.mimeType; // mime type to match the file
		
		PlayFabAdminAPI.GetContentUploadUrl(request, OnGetContentUploadURLSuccess, OnPlayFabError);
	}


	void OnGetContentUploadURLSuccess(GetContentUploadUrlResult result)
	{
		byte[] fileContents = sd.MainAvatarFaceTexture.EncodeToPNG();
		//byte[] fileContents = File.ReadAllBytes(assetPath);
		PutFile(result.URL, fileContents);
	}


	void GetContentDownloadURL()
	{
		GetContentDownloadUrlRequest request = new GetContentDownloadUrlRequest ();
		request.Key = this.contentKey;
		PlayFabClientAPI.GetContentDownloadUrl (request, OnGetContentDownloadURLSuccess, OnPlayFabError);
	}


	void OnGetContentDownloadURLSuccess(GetContentDownloadUrlResult result)
	{
		StartCoroutine(GetFile(result.URL));
		
	}


	void OnPlayFabError(PlayFabError error)
	{
		Debug.LogWarning(string.Format("ERROR: [{0}] -- {1}", error.Error, error.ErrorMessage));
	}


	public void PutFile(string putURL, byte[] payload)
	{
		var request = (HttpWebRequest)WebRequest.Create(putURL);
		request.Method = "PUT";
		request.ContentType = this.mimeType;
		
		if (payload != null)
		{
			Stream dataStream = request.GetRequestStream();
			dataStream.Write(payload, 0, payload.Length);
			dataStream.Close();
		}
		else
		{
			Debug.LogWarning(string.Format("ERROR: Byte arrry was empty or null"));
			return;
		}
		
		Debug.Log("Starting HTTP PUT...");
		HttpWebResponse response = (HttpWebResponse)request.GetResponse();
		
		if(response.StatusCode == HttpStatusCode.OK)
		{
			Debug.Log("...HTTP PUT Successful");
			this.isImageUploaded = true;
		}
		else
		{
			Debug.LogWarning(string.Format("ERROR: [{0}] -- {1}", response.StatusCode, response.StatusDescription));
		}
	}


	public IEnumerator GetFile(string getURL)
	{
		// Start a download of the given URL
		var www = new WWW(getURL);
		
		// wait until the download is done
		yield return www;
		
		Debug.Log("...HTTP GET Successful");
		
		// assign the downloaded image to a Texture2D
		this.downloadedImage.LoadImage(www.bytes);
		this.isImageDownloaded = true;
	}
}


And then you will get the same error.

WebException: Error writing request: The authentication or decryption has failed. System.Net.WebConnectionStream.WriteHeaders () System.Net.WebConnectionStream.SetHeaders (System.Byte[] buffer) (wrapper remoting-invoke-with-check) System.Net.WebConnectionStream:SetHeaders (byte[]) System.Net.HttpWebRequest.SendRequestHeaders (Boolean propagate_error) UnityEngine.Debug:LogException(Exception) PlayFab.Internal.<MakeApiCall>c__AnonStoreyC:<>m__4(String) (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:137) PlayFab.Internal.<Post>c__Iterator5:MoveNext() (at Assets/PlayFabSdk/Shared/Internal/PlayFabHttp/PlayFabWWW.cs:212)

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

key-holder avatar image key-holder commented ·
upload the Add Component -> ImgFileIO

When you press the upload button and then you will get the same error.

0 Likes 0 ·

1 Answer

·
1807605288 avatar image
1807605288 answered

All known instances of this issue should have been fixed by version 2.5.160815:

https://api.playfab.com/releaseNotes/#160815

Please let us know what version of our SDK you're using, and try updating to 2.9.160919:

https://github.com/PlayFab/UnitySDK/releases/tag/2.9.160919

Let us know if that resolves the problem for you.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.